[LeetCode] Plus One
2014-04-08 16:17
357 查看
Total Accepted: 9100 Total Submissions: 29949
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.
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.
public class Solution { public int[] plusOne(int[] digits) { int carry = 1; for (int i = digits.length-1; i >= 0; i--) { int temp = digits[i]+carry; digits[i] = temp%10; if (temp > 9 ) carry = 1; else carry = 0; } if (carry == 0) return digits; // 100000000... int[] tmp = new int[digits.length+1]; tmp[0] = 1; return tmp; } }
相关文章推荐
- LeetCode:Plus One
- LeetCode题解:Plus One
- 【leetcode】Plus One
- 【LeetCode with Python】 Plus One
- 【LeetCode】Plus One
- 【LeetCode】66. Plus One
- [LeetCode]Plus One
- leetcode 66_Plus One C++
- LeetCode(29)-Plus One
- leetcode 66. Plus One
- leetcode刷题之旅——66Plus One
- 2018.3.12 leetcode打卡 #66 plus one
- 【leetcode】Array—— Plus One(66)
- LeetCode编程练习 - Plus One学习心得
- LeetCode 066 Plus One
- leetcode--66.Plus One
- Leetcode:66. Plus One(JAVA)
- [LeetCode]66 Plus One
- LeetCode: Plus One
- [LeetCode]66-Plus One