当前位置:网站首页>LeetCode_66(加一)
LeetCode_66(加一)
2022-07-01 04:37:00 【***】
题目描述:
给定一个由 整数 组成的 非空 数组所表示的非负整数,在该数的基础上加一。
最高位数字存放在数组的首位, 数组中每个元素只存储单个数字。
你可以假设除了整数 0 之外,这个整数不会以零开头。
示例 1:
输入:digits = [1,2,3]
输出:[1,2,4]
解释:输入数组表示数字 123。
示例 2:
输入:digits = [4,3,2,1]
输出:[4,3,2,2]
解释:输入数组表示数字 4321。
示例 3:
输入:digits = [0]
输出:[1]
提示:
1 <= digits.length <= 100
0 <= digits[i] <= 9
class Solution {
public int[] plusOne(int[] digits) {
for (int i = digits.length-1; i >=0 ; i--) {
if(digits[i]!=9){
digits[i]++;
return digits;
}
digits[i]=0;
}
int[] res=new int[digits.length+1];
res[0]=1;
return res;
}
}
边栏推荐
- 【硬十宝典】——1.【基础知识】电源的分类
- Leecode record 1351 negative numbers in statistical ordered matrix
- 2022 question bank and answers for safety production management personnel of hazardous chemical production units
- 2022年煤气考试题库及在线模拟考试
- 2022 hoisting machinery command registration examination and hoisting machinery command examination registration
- LM小型可编程控制器软件(基于CoDeSys)笔记十九:报错does not match the profile of the target
- Pytorch(三) —— 函数优化
- 神经网络-最大池化的使用
- Maixll-Dock 使用方法
- Pytest automated testing - compare robotframework framework
猜你喜欢

How to use maixll dock

Obtain detailed ideas for ABCDEF questions of 2022 American Games

RuntimeError: mean(): input dtype should be either floating point or complex dtypes.Got Long instead

2022 t elevator repair question bank and simulation test

2022年聚合工艺考试题及模拟考试
![[learn C and fly] S1E20: two dimensional array](/img/68/34fad73ff23d3e0719ef364fc60cb5.jpg)
[learn C and fly] S1E20: two dimensional array

尺取法:有效三角形的个数

Applications and features of VR online exhibition

神经网络-卷积层

Measurement of quadrature axis and direct axis inductance of three-phase permanent magnet synchronous motor
随机推荐
【硬十宝典目录】——转载自“硬件十万个为什么”(持续更新中~~)
All in all, the low code still needs to solve these four problems
Pytorch(四) —— 可视化工具 Visdom
Common UNIX Operation and maintenance commands of shell
Ospfb notes - five messages [ultra detailed] [Hello message, DD message, LSR message, LSU message, lsack message]
2022 gas examination question bank and online simulation examination
Kodori tree board
Programs and processes, process management, foreground and background processes
How do I sort a list of strings in dart- How can I sort a list of strings in Dart?
[pat (basic level) practice] - [simple simulation] 1064 friends
神经网络-非线性激活
TASK04|数理统计
JS rotation chart
VR线上展览所具备应用及特色
尺取法:有效三角形的个数
Haskell lightweight threads overhead and use on multicores
LM小型可编程控制器软件(基于CoDeSys)笔记二十:plc通过驱动器控制步进电机
Cmake selecting compilers and setting compiler options
This sideline workload is small, 10-15k, free unlimited massage
Why is Hong Kong server most suitable for overseas website construction