当前位置:网站首页>Leetcode66. 加一
Leetcode66. 加一
2022-07-29 12:52:00 【Java全栈研发大联盟】
题目传送地址:https://leetcode.cn/problems/plus-one/
运行效率:
代码如下:
public static int[] plusOne(int[] digits) {
int lastIndex = digits.length - 1;
digits[lastIndex]++;//末尾的数加1
while (lastIndex > 0 && digits[lastIndex] == 10) {
digits[lastIndex] = 0;
lastIndex--;
digits[lastIndex]++;
}
if (lastIndex == 0 && digits[0] == 10) {
//比如 999 如果再加1的话,那就是1000
digits[0]=0;
int[] res = new int[digits.length + 1];
res[0] = 1;
System.arraycopy(digits, 0, res, 1, digits.length);
return res;
}
return digits;
}
边栏推荐
猜你喜欢
随机推荐
Dataset:FIFA 2018 Statistics数据集(Predict FIFA 2018 Man of the Match预测2018年国际足联最佳球员)的简介、下载、使用方法之详细攻略
Container is changed | deploy MySQL cluster in the Rancher
传奇版本添加npc修改增加npc方法以及配置参数教程
浅谈防勒索病毒方案之主机加固
近期论文总结
npm install 报错问题解决合集
xxl-job源码解析(技术分享)
Interceptors and filters (3) @interface custom annotation interception
MySQL 视图(详解)
2022年年中总结:行而不辍,未来可期
MySQL基础篇(四)-- 数据表的基本操作
The interviewer was stunned by the self-growth of 4 mainstream database IDs in one breath
何享健“A拆A”又败一局,美的旗下美智光电终止创业板IPO
关于ESI研究前沿的思考和使用方法研究
JS advanced four (map, reduce, filter, sort, arrow function, class inheritance, yield)
CentOS7安装Oracle数据库的全流程
年轻人开始“反大牌”,有钱也不买
MySQL八股文背诵版
snap软件中哨兵2A数据预处理及六种常用植被指数的计算
hash table 实现代码









