LeetCode(67)Plus One
2014-10-16 13:45
344 查看
题目如下:
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.
题目分析:
简单题目,模拟加法运算即可。
我的代码:
class Solution { public: vector<int> plusOne(vector<int> &digits) { int new_digit = 0; int over_flow = 0; vector<int> result; digits[digits.size() - 1] += 1; for (int i = digits.size() - 1; i >= 0; --i) { new_digit = (over_flow + digits[i]) % 10; over_flow = (over_flow + digits[i]) / 10; digits[i] = new_digit ; } result.assign(digits.begin(), digits.end()); if (over_flow > 0) result.insert(result.begin(), 1); return result; } };
相关文章推荐
- 【LeetCode】66 & 67- Plus One & Add Binary
- leetcode Plus One
- LeetCode Plus One
- Leetcode 66 Plus One STL
- LeetCode Plus One Linked List
- LeetCode OJ Plus One
- LeetCode--plus-one
- [leetcode] 369. Plus One Linked List 解题报告
- leetcode Plus One
- leetcode 66.Plus One python
- 66. Plus One LeetCode
- LeetCode "Plus One Linked List"
- Plus One @LeetCode
- Plus One leetcode java
- Leetcode Plus One
- [LeetCode]Plus One@python
- leetcode Plus one
- LeetCode 369. Plus One Linked List
- LeetCode Plus One
- 【Leetcode】之Plus One