当前位置:网站首页>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;
}
}
边栏推荐
- Ospfb notes - five messages [ultra detailed] [Hello message, DD message, LSR message, LSU message, lsack message]
- [deep learning] (4) decoder mechanism in transformer, complete pytoch code attached
- 2022年上海市安全员C证考试题模拟考试题库及答案
- 2022年G1工业锅炉司炉特种作业证考试题库及在线模拟考试
- Difference between cookie and session
- 【硬十宝典目录】——转载自“硬件十万个为什么”(持续更新中~~)
- 2022年聚合工艺考试题及模拟考试
- Task04 | statistiques mathématiques
- Simple implementation of slf4j
- 2022 Shanghai safety officer C certificate examination question simulation examination question bank and answers
猜你喜欢

2022年化工自动化控制仪表操作证考试题库及答案

OdeInt與GPU

(12) Somersault cloud case (navigation bar highlights follow)

The junior college students were angry for 32 days, four rounds of interviews, five hours of soul torture, and won Ali's offer with tears

神经网络-非线性激活

pytorch 卷积操作

离线安装wireshark2.6.10

RuntimeError: “max_pool2d“ not implemented for ‘Long‘

2022年G1工业锅炉司炉特种作业证考试题库及在线模拟考试

Internet winter, how to spend three months to make a comeback
随机推荐
Maixll-Dock 使用方法
Basic usage, principle and details of session
Maixll dock quick start
总结全了,低代码还需要解决这4点问题
I also gave you the MySQL interview questions of Boda factory. If you need to come in and take your own
JS rotation chart
How to choose the right server for website data collection?
2022 polymerization process test questions and simulation test
pytorch神经网络搭建 模板
(12) Somersault cloud case (navigation bar highlights follow)
CF1638E. Colorful operations Kodori tree + differential tree array
Pytorch(三) —— 函数优化
This sideline workload is small, 10-15k, free unlimited massage
2022 gas examination question bank and online simulation examination
Difference between cookie and session
Cmake selecting compilers and setting compiler options
Dede collection plug-in does not need to write rules
Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom
【硬十宝典目录】——转载自“硬件十万个为什么”(持续更新中~~)
Day 52 - tree problem