当前位置:网站首页>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;
}
边栏推荐
- Framework common annotation explanation
- 传奇版本添加npc修改增加npc方法以及配置参数教程
- C语言小游戏------贪吃蛇----小白专用
- torch使用总结
- html+css+php+mysql实现注册+登录+修改密码(附完整代码)
- [Cloud native] Introduction and use of Feign of microservices
- 学习的时候碰见的一个sql问题,希望大佬们可以解答一二?
- xxl-job源码解析(技术分享)
- Sql file import database - nanny level tutorial
- Windows系统Mysql8版本的安装教程
猜你喜欢
xxl-job源码解析(技术分享)
pycharm专业版使用
npm出现报错 npm WARN config global `--global`, `--local` are deprecated. Use `--location=global
超年轻!34岁教授,任985王牌学院副院长!
近期论文总结
MySql字符串拆分实现split功能(字段分割转列、转行)
3D Laser SLAM: Interpretation of LeGO-LOAM Papers---Hardware System Part
Nacos hierarchical storage model - the cluster configuration and NacosRule load balance
【C#】WCF和TCP消息通信练习,实现聊天功能
Meta,元宇宙和广告双败的一季
随机推荐
The strategy pattern replacement if the else
[网鼎杯 2020 半决赛]AliceWebsite
常坐飞机的你,为什么老惦记着“升舱”?
关于ESI研究前沿的思考和使用方法研究
Go-Excelize API源码阅读(七)—— CopySheet(from, to int)
浅谈防勒索病毒方案之主机加固
DVWA full level customs clearance tutorial
How Navicat Connects to MySQL
传奇人形怪爆率怎么设置?人形怪增加教程
Sql文件导入数据库-保姆级教程
npm出现报错 npm WARN config global `--global`, `--local` are deprecated. Use `--location=global
基于对象的实时空间音频渲染丨Dev for Dev 专栏
Navicat如何连接MySQL
MySQL八股文背诵版
adb for mysql在什么平台进行开发啊
Mysql stored procedures, rounding
Framework common annotation explanation
Mysql各个大版本之间的区别
JS advanced four (map, reduce, filter, sort, arrow function, class inheritance, yield)
C# autoCAD 几个经常用到的功能代码。