当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
如何监控海外服务器性能
snap软件中哨兵2A数据预处理及六种常用植被指数的计算
CentOS7安装Oracle数据库的全流程
理解yolov7网络结构
[Cloud native] Introduction and use of Feign of microservices
近期论文总结
轻松学Pytorch-Pytorch可视化
JUC阻塞队列-ArrayBlockingQueue
C# 1秒跑一个数字的展示,主要练习 事件相关内容
Navicat如何连接MySQL
hash table 实现代码
图解 Attention(完整版)!
关于ESI研究前沿的思考和使用方法研究
一起来侃个球
mongo根据时间字段进行时间格式化并进行统计
The whole process of installing Oracle database on CentOS7
IDEA2021.2安装与配置(持续更新)
mysql5.7.35安装配置教程【超级详细安装教程】
Mysql进阶优化篇01——四万字详解数据库性能分析工具(深入、全面、详细,收藏备用)
【云原生】微服务之Feign的介绍与使用





![[Numpy] np.select](/img/d6/5dfa767ad24dab3f7289d861011d00.jpg)



