LeetCode: 66. Plus One
来源:互联网 发布:百度云总显示网络异常 编辑:程序博客网 时间:2024/06/05 07:37
LeetCode: 66. Plus One
题目描述
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.
You may assume the integer do not contain any leading zero, except the number 0 itself.
The digits are stored such that the most significant digit is at the head of the list.
题目大意: 给定一个用数组存的大数, 计算它加一之后的值。
解题思路
直接按照小学计算两个数的加法的方法模拟。
AC代码
class Solution {public: vector<int> plusOne(vector<int>& digits) { reverse(digits.begin(), digits.end()); int carryNum = 1; for(size_t i = 0; i < digits.size(); ++i) { digits[i] += carryNum; carryNum = digits[i] / 10; digits[i] %= 10; } if(carryNum != 0) digits.push_back(carryNum); reverse(digits.begin(), digits.end()); return digits; }};
阅读全文
1 0
- [LeetCode]66.Plus One
- LeetCode --- 66. Plus One
- [Leetcode] 66. Plus One
- [leetcode] 66.Plus One
- [leetcode] 66. Plus One
- Leetcode-66. Plus One
- 【leetcode】66. Plus One
- 66. Plus One LeetCode
- 【LeetCode】66. Plus One
- [LeetCode]66. Plus One
- 【LeetCode】66. Plus One
- LeetCode 66. Plus One
- LeetCode *** 66. Plus One
- leetcode 66. Plus One
- 【leetcode】66. Plus One
- leetcode 66. Plus One
- [LeetCode]66. Plus One
- Leetcode 66. Plus One
- 工作中小细节总结(三)
- Spring AOP---切面编程基础(动态代理)
- MySQL学习笔记——20170811
- Codeforces Round #428 (Div. 2) Game of the Rows (思维)
- Java基础总结-基本语法概念-1
- LeetCode: 66. Plus One
- C/C++指针错误与调试相关学习总结
- Linux命令:pwd,切换用户,切换宿主目录,.,..,-,相对路径绝对路径
- Linux下编程求绝对路径和读取目录
- js显示动态时间的方法
- 活了这么久,突然感觉像白开水
- HttpClient4.5.3设置代理(Proxy)访问目标地址
- Leetcode题目总结-Math-如何判断素数?
- Leetcode-19: Remove Nth Node From End of List