LeetCode-Plus One
2014-09-13 21:10
197 查看
作者:disappearedgod
文章出处:/article/3730225.html
时间:2014-9-13
题目
Total Accepted: 19009 Total
Submissions: 60196My Submissions
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.
Have you been asked this question in an interview?
Solution(持续更新,java>c++)
文章出处:/article/3730225.html
时间:2014-9-13
题目
Plus One
Total Accepted: 19009 TotalSubmissions: 60196My Submissions
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.
Have you been asked this question in an interview?
想法
代码
public class Solution { public int[] plusOne(int[] digits) { int carry = 1; int[] arr = new int[digits.length + 1]; int i = digits.length-1; for(; i >= 0; i--){ digits[i] += carry; carry = digits[i] / 10; digits[i] %= 10; arr[i] = digits[i]; } if(carry == 0) return digits; else{ arr[0] = carry; return arr; } } }
结果
My Submissions for Plus One
Submit Time | Status | Run Time | Language |
---|---|---|---|
3 minutes ago | Accepted | 416 ms | java |
3 minutes ago | Accepted | 408 ms | java |
返回
LeetCodeSolution(持续更新,java>c++)
相关文章推荐
- LeetCode 066 Plus One
- leetcode-66 plus one
- leetcode66: Plus One
- LeetCode:Plus One
- LeetCode -- 66. Plus One
- Leetcode: Plus One
- LeetCode066 Plus One
- [LeetCode][JavaScript]Plus One
- [leetcode] Plus One
- Leetcode 66 Plus One
- LeetCode - Plus One
- leetcode--66. Plus One
- LeetCode66——Plus One(一个整数用数组存储,然后在末尾加1)
- leetcode 65:Plus One
- Leetcode: Plus One
- leetcode_question_66 Plus One
- Leetcode65 Plus One
- [LeetCode] Plus One
- [LeetCode] Plus One
- leetcode-66 Plus One