当前位置:网站首页>[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}));
}
}
边栏推荐
- twenty million two hundred and twenty thousand seven hundred and one
- 死锁的处理策略—预防死锁、避免死锁、检测和解除死锁
- Single step debugging analysis of rxjs observable of operator
- 旅游管理系统
- 陈天奇的机器学习编译课(免费)
- nn. Parameter] pytoch feature fusion adaptive weight setting (learnable weight use)
- Fully annotated SSM framework construction
- 友善串口助手使用教程_友善串口调试助手怎么进行配置-友善串口调试助手使用教程…
- Understanding of indexes in MySQL
- Awoo's favorite problem (priority queue)
猜你喜欢

今日睡眠质量记录71分

【图像分割】2021-SegFormer NeurIPS

Appium自动化测试基础 — APPium安装(一)

Delete AWS bound credit card account

Metauniverse may become a new direction of Internet development

使用 EMQX Cloud 实现物联网设备一机一密验证

Appium automated testing foundation - Supplement: introduction to desired capabilities parameters

多图预警~ 华为 ECS 与 阿里云 ECS 对比实战

Favorite transaction code management tool in SAP GUI

Understanding of indexes in MySQL
随机推荐
Slope compensation
3DE 资源没东西或不对
There is no signal in HDMI in computer games caused by memory, so it crashes
ECMAScript 2022 正式发布,有你了解过的吗?
性能测试计划怎么编写
多图预警~ 华为 ECS 与 阿里云 ECS 对比实战
切面条 C语言
MySQL数据库详细学习教程
Mysql database detailed learning tutorial
功能测试报告的编写
104. SAP UI5 表格控件的支持复选(Multi-Select)以及如何用代码一次选中多个表格行项目
2020-ViT ICLR
Appium automated testing foundation - Supplement: introduction to desired capabilities parameters
MySQL的存储过程
Yyds dry goods inventory # solve the real problem of famous enterprises: egg twisting machine
Explain kubernetes network model in detail
Mysql5.7 set password policy (etc. three-level password transformation)
Slope compensation
小红书Scheme跳转到指定页面
Delete AWS bound credit card account