leetcode 刷题之路 75 Plus One
2014-08-10 19:25
435 查看
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.
用vector表示一个数,对这个数进行加1操作。
AC code:
The digits are stored such that the most significant digit is at the head of the list.
用vector表示一个数,对这个数进行加1操作。
AC code:
class Solution { public: vector<int> plusOne(vector<int> &digits) { int sum=1,n=digits.size(); for(int i=n-1;i>=0;i--) { digits[i]=(digits[i]+1); if(digits[i]<10) break; else { digits[i]%=10; if(i==0) digits.insert(digits.begin(),1); } } return digits; } };
相关文章推荐
- Plus One - Leetcode
- Two Sum-LeetCode-弱菜进击之路
- leetCode75. Sort Colors
- [LeetCode66]Plus One
- LeetCode 75. Sort Colors
- Leetcode 75. Sort Colors
- leetCode 66.Plus One (+1问题) 解题思路和方法
- 【LeetCode】75. Sort Colors (3 solutions)
- LeetCode 75. Sort Colors
- Leetcode - 75. Sort Colors - Dutch national flag problem - Partition
- Leetcode75 Sort Colors
- LeetCode: 66. Plus One
- LeetCode | Plus One
- 【leetcode75】Intersection of Two Arrays(数组的交集)
- leetcode 75: Reverse digits of an integer.
- LeetCode(75)Sort Colors (荷兰三色旗问题 Dutch National Flag)
- LeetCode 066 Plus one
- LeetCode 第 66 题 (Plus One)
- 【leetcode】【66】Plus One
- leetcode 66. Plus One