当前位置:网站首页>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;
}
边栏推荐
- 【云原生】-Docker容器迁移Oracle到MySQL
- C语言小游戏------贪吃蛇----小白专用
- Go - reading (7), CopySheet Excelize API source code (the from and to the int)
- 苹果手机用久了卡顿,学会这样清理缓存,清理后和新机一样流畅
- APP local number one-click login
- 用支持LaTex的Markdown语句编辑一个数学公式
- conda环境创建及复制
- [MySQL view] View concept, create, view, delete and modify
- 【MySQL视图】视图的概念、创建、查看、删除和修改
- The whole process of installing Oracle database on CentOS7
猜你喜欢
随机推荐
Chapter 6 c + + primer notes 】 【 function
pycharm专业版使用
【C#】WCF和TCP消息通信练习,实现聊天功能
【c ++ primer 笔记】第6章 函数
MLX90640 红外热成像仪测温传感器模块开发笔记(九)
[based] GO language. Why do I have to learn Golang and introduction to the language universal
MySQL基础篇(三)-- 数据类型
MIT指出公开预训练模型不能乱用
70行代码撸一个桌面自动翻译神器!
"Pure theory" FPN (Feature Pyramid Network)
MySQL如何对SQL做prepare预处理(解决IN查询SQL预处理仅能查询出一条记录的问题)
The whole process of installing Oracle database on CentOS7
栈“后进先出”和队列中“先进先出”的含义
npm install 报错问题解决合集
2022年编程语言排名,官方数据来了,让人大开眼界
APP本机号码一键登录
Container is changed | deploy MySQL cluster in the Rancher
TiDB upgrade share with case (TiDB v4.0.1 to v5.4.1)
SIP系统组成格式
[WeChat applet] One article to solve button, input, image components









