当前位置:网站首页>[daily training] 66 add one-tenth
[daily training] 66 add one-tenth
2022-07-01 22:49:00 【Puppet__】
subject
Given a by Integers Composed of Non empty The nonnegative integer represented by an array , Add one to the number .
The highest digit is placed at the top of the array , Each element in the array stores only a single number .
You can assume that except for integers 0 outside , This integer will not start with zero .
Example 1:
Input :digits = [1,2,3]
Output :[1,2,4]
explain : Input array represents number 123.
Example 2:
Input :digits = [4,3,2,1]
Output :[4,3,2,2]
explain : Input array represents number 4321.
Example 3:
Input :digits = [0]
Output :[1]
Tips :
1 <= digits.length <= 100
0 <= digits[i] <= 9
Code
package dayLeetCode;
public class dayleetcode66 {
/** * The key is to deal with 9 * (1) The last one is not 9 Words , direct +1 * (2) The last few are 9 Words , Find the first non from back to front 9 The elements of , Put it +1, And then 9 Set all 0 * (3) All is 9 Words , Expand , Add a... At the top 1 * @param digits * @return */
public int[] plusOne(int[] digits) {
int n = digits.length;
for (int i = n -1; i >= 0 ; i--) {
if (digits[i] != 9){
digits[i]++;
for (int j = i + 1; j < n; j++){
digits[j] = 0;
}
return digits;
}
}
digits = new int[n + 1];
digits[0] = 1;
return digits;
}
public static void main(String[] args) {
dayleetcode66 obj = new dayleetcode66();
System.out.println(obj.plusOne(new int[]{
1, 2, 3}));
}
}
边栏推荐
- 【QT小作】封装一个简单的线程管理类
- mixconv代码
- SAP UI5 应用开发教程之一百零四 - SAP UI5 表格控件的支持复选(Multi-Select)以及如何用代码一次选中多个表格行项目
- 14年本科毕业,3个月转行软件测试月薪13.5k,32的岁我终于找对了方向
- 使用 Three.js 实现'雪糕'地球,让地球也凉爽一夏
- rxjs Observable of 操作符的单步调试分析
- Pytorch nn. functional. Simple understanding and usage of unfold()
- JVM有哪些类加载机制?
- Slope compensation
- Use three JS realize the 'ice cream' earth, and let the earth cool for a summer
猜你喜欢
Compensation des créneaux horaires
Fully annotated SSM framework construction
使用 Three.js 实现'雪糕'地球,让地球也凉爽一夏
Slope compensation
vSphere+、vSAN+来了!VMware 混合云聚焦:原生、快速迁移、混合负载
好友新书发布,祝贺(送福利)
H5 model trained by keras to tflite
Single step debugging analysis of rxjs observable of operator
“信任机器”为发展赋能
台积电全球员工薪酬中位数约46万,CEO约899万;苹果上调日本的 iPhone 售价 ;Vim 9.0 发布|极客头条
随机推荐
固定资产管理子系统报表分为什么大类,包括哪些科目
死锁的处理策略—预防死锁、避免死锁、检测和解除死锁
MySQL中对于事务的理解
友善串口助手使用教程_友善串口调试助手怎么进行配置-友善串口调试助手使用教程…
【JetCache】JetCache的使用方法与步骤
[literacy] deep / shallow, local / global features in machine learning image processing
[C language] detailed explanation of malloc function [easy to understand]
20220701
Pytorch nn. functional. Simple understanding and usage of unfold()
447-哔哩哔哩面经1
RestTemplate 远程调用工具类
internal field separator
Use three JS realize the 'ice cream' earth, and let the earth cool for a summer
小红书Scheme跳转到指定页面
map容器
[untitled]
Mysql——》MyISAM存储引擎的索引
Multi picture alert ~ comparison of Huawei ECs and Alibaba cloud ECS
人体姿态估计的热图变成坐标点的两种方案
下班前几分钟,我弄清了v-model与.sync的区别