【leetcode】【66】Plus One
来源:互联网 发布:matlab定义二维数组 编辑:程序博客网 时间:2024/05/20 23:58
一、问题描述
Given a non-negative number represented as an array of digits, plus one to the number.
The digits are stored such that the most significant digit is at the head of the list.
二、问题分析
数字加1问题。只不过数字用一个数组来存储,且数组的低索引存数字的高位。只需要注意进位即可。可以直接在原数组上操作,如果最后还有进位再另行copy到一个新的数组。
三、Java AC代码
public int[] plusOne(int[] digits) { int carry = 1;for(int i=digits.length-1;i>=0;--i){int temp = digits[i];temp = (temp+carry)%10;carry = (digits[i]+carry)/10;digits[i] = temp;}if (carry == 1) {int [] res = new int[digits.length+1];res[0] = 1;System.arraycopy(digits, 0, res, 1, digits.length);return res;}return digits; }
0 0
- leetcode 66 Plus One
- [leetcode 66] Plus One
- [LeetCode 66]Plus One
- leetcode ||66、 Plus One
- leetcode-66 plus one
- LeetCode 66 Plus One
- Plus One - LeetCode 66
- leetcode-66 Plus One
- Leetcode[66]-Plus One
- 【leetcode】【66】Plus One
- leetcode[66]:Plus One
- leetcode-66-Plus One
- leetcode 66:plus one
- Leetcode# 66 Plus One
- leetcode 66: Plus One
- [LeetCode]66-Plus One
- Leetcode#66||Plus One
- [Leetcode]#66 Plus One
- JS事件之鼠标事件
- 【bzoj4013】[HNOI2015]实验比较 树形dp+组合数学
- Error>: CGContextDrawImage: invalid context 0x0. If you want to see the backtrace, please set CG_CON
- 九度题目1173
- 【代码笔记】iOS-浮点数处理并去掉多余的0
- 【leetcode】【66】Plus One
- chrome工具Postman使用图文教程
- 安装mysql5.7.11遇到的问题
- java装饰者模式
- php编辑ppt方法 PHPPowerPoint类 学习
- openSuse Leap 42.1 如何设置双击打开文件夹及打开触摸板滚动
- 程序员怎么获得高工资
- 排序算法之shell排序
- JMS简介与ActiveMQ实战