[LeetCode] Plus One 解题报告
2016-01-12 11:07
387 查看
Given a number represented as an array of digits, plus one to the number.
» Solve this problem
[解题思路]
加位与进位。模拟。
» Solve this problem
[解题思路]
加位与进位。模拟。
[code]1: vector<int> plusOne(vector<int> &digits) { 2: // Start typing your C/C++ solution below 3: // DO NOT write int main() function 4: int cary=1, sum =0; 5: vector<int> result(digits.size(),0); 6: for(int i = digits.size()-1; i>=0; i--) 7: { 8: sum = cary+digits[i]; 9: cary = sum/10; 10: result[i] = sum%10; 11: } 12: if(cary >0) 13: { 14: result.insert(result.begin(), cary); 15: } 16: return result; 17: }
相关文章推荐
- [LeetCode] Populating Next Right Pointers in Each Node 解题报告
- [LeetCode] Populating Next Right Pointers in Each Node II 解题报告
- [LeetCode] Recover Binary Search Tree 解题报告
- [LeetCode] Pow(x, n) 解题报告
- [LeetCode] Remove Duplicates from Sorted Array 解题报告
- [LeetCode] Remove Duplicates from Sorted Array II 解题报告
- [LeetCode] Remove Duplicates from Sorted List 解题报告
- [LeetCode] Remove Element 解题报告
- Attribute is missing the Android namespace prefix(属性是失踪的Android名称空间前缀)
- Codeforces Round #309 (Div. 2) C
- JavaScript正则表达式
- kohana安装总结
- vs2005中microsoft ado data control 6.0控件问题
- AC自动机 LA 4670 Dominating Patterns
- pt-table-checksum 针对某个库做数据校验
- 什么是可重入锁
- LeetCode:Isomorphic Strings
- Ubuntu下MySql配置
- [Leetcode] Distinct Subsequences 解题报告
- [LeetCode] Divide Two Integers 解题报告