leetCode 66. Plus One 数组
2016-08-08 23:28
357 查看
66. Plus One
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,求得到的新数组。高位在前。
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,求得到的新数组。高位在前。
class Solution { public: vector<int> plusOne(vector<int>& digits) { int len = digits.size(); for(int i = len - 1; i >= 0;i--) { if(digits[i] + 1 < 10) { digits[i] = digits[i] + 1; break; } else { digits[i] = 0; if(i == 0) { digits.clear(); digits.push_back(1); for(int j = 0 ;j < len; j++) digits.push_back(0); } } } return digits; } };2016-08-08 23:27:58
相关文章推荐
- [leetcode] 【数组】 66. Plus One
- LeetCode-66:Plus One (数组看作数据 加1)
- leetcode_66. Plus One 数组表示的大数加1
- LeetCode 66. Plus One--数字数组最后一个元素加1,保持进位
- LeetCode_66. Plus One_数组加一
- LeetCode WIith JS || 66. Plus One [数组存储的数据加一]
- LeetCode66——Plus One(一个整数用数组存储,然后在末尾加1)
- LeetCode_66. Plus One_数组加一
- leetcode 66---Plus One 进位 数组
- leetcode[66]Plus One
- leetcode_数组_相关内容_1(48-66-88-118-119)
- Plus One - LeetCode 66
- 【leetcode】【66】Plus One
- Leetcode[66]-Plus One
- leetcode ||66、 Plus One
- LeetCode_66---Plus One
- [Leetcode 4] 66 Plus One
- 66:Plus One【数组】【数学】
- leetcode-66-Plus One
- leetcode 66. Plus One