LintCode 407. 加一
来源:互联网 发布:linux下c语言编程 编辑:程序博客网 时间:2024/05/16 01:27
思路:
逐数字相加,采用进位标志标记是否需要进位
代码:
class Solution {public: /** * @param digits a number represented as an array of digits * @return the result */ vector<int> plusOne(vector<int>& digits) { // Write your code here int len = digits.size(), tmp = 0, plus = 1; for(int i = len - 1;i >= 0; --i){ tmp = digits[i] + plus; digits[i] = tmp % 10; plus = tmp / 10; }// for if(0 == plus) return digits; digits.push_back(0); for(int i = len; i > 0; --i) digits[i] = digits[i - 1]; digits[0] = 1; return digits; }};
0 0
- LintCode 407. 加一
- [LintCode]407.加一
- LintCode PlusOne 加一
- lintcode-加一-407
- LintCode : 加一
- 加一(LintCode)
- lintcode----加一
- 加一,lintcode
- LintCode 407-加一
- LintCode(加一)
- 【数组】[Lintcode]加一
- lintcode : 加一
- lintcode加一
- 加一 -LintCode
- [Lintcode] #407 加一
- 【Lintcode】加一
- lintcode 加一(Plus One )(Java)
- LintCode 第407题 加一
- PostgreSQL中 drop table指令出现ERROR: cannot drop table userinfo because other objects depend on it
- 金字塔
- hdu 5015-矩阵快速幂
- trie树(字典树)
- 职场里根本没人管你怎么办?
- LintCode 407. 加一
- WINDOWS虚拟机 UBUNTU 14.04 下安装ROS经验
- php中利用session保存用户登陆信息
- c++ primer plus学习笔记
- String Matching Content Length
- zb的生日
- 自定义View之边框文字,闪烁发光文字
- 八大排序
- 【U3D学习】塔防游戏03