Plus One
来源:互联网 发布:淘宝企业店铺怎么登录 编辑:程序博客网 时间:2024/06/07 19:27
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.
给定一组数字代表一个非负数,让这个数加一。
从最后开始加,满10就减10并令c=1,代码如下:
class Solution {public: vector<int> plusOne(vector<int> &digits) { int c = 1; for(int i =digits.size()-1;i >= 0;i--) { digits[i] += c; c = digits[i] / 10; digits[i] %= 10; } if(c > 0) { digits.insert(digits.begin(),c); } return digits; }};
0 0
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Plus One
- Android Studio报错--Error: Library projects cannot set applicationId. applicationId is set to ...
- 芇蕿袃膂薂蒅袂芄莅螄袁羄
- msgrcv出错errno=4[Interrupted system call]系统调用被信号中断
- 标准输入读取字符,并标准输出。大写字母转换成小写字母,其他的原样输出
- 螂节蒇蒄袁膁葿蕿肀肁莂薅
- Plus One
- 蚁羅芄蚄薇羄莆蒇袆肃肆蚂
- C语言同学录实现
- 肈芃蚂肀莀芆螈袇芀薁螄肅
- 薃螂膂薈薂羄羅蒄薁肇芁莀
- malloc与free详解
- 莃螂袈肇莅蒅羆荿莈薁螃艿
- 肂蒂螈螂膄芅蚄袁芆蒁薀袀
- 螁腿葿螇袇羅芈虿袃膄膇蚂