66. Plus One
来源:互联网 发布:高通垄断 知乎 编辑:程序博客网 时间:2024/05/20 05:05
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.
class Solution {
public:
vector<int> plusOne(vector<int>& digits) {
bool carry = true;
for(int i=digits.size()-1; i >= 0 && carry; i--) {
carry = (++digits[i]%=10) == 0;
}
if(carry) {
digits.insert(digits.begin(), 1);
}
return digits;
}
};
阅读全文
0 0
- [LeetCode]66.Plus One
- LeetCode --- 66. Plus One
- [Leetcode] 66. Plus One
- [leetcode] 66.Plus One
- 66. Plus One
- 66. Plus One
- [leetcode] 66. Plus One
- Leetcode-66. Plus One
- 【leetcode】66. Plus One
- 66. Plus One
- 66. Plus One LeetCode
- 66. Plus One
- 66. Plus One
- 66. Plus One
- 66. Plus One
- 66. Plus One
- 【LeetCode】66. Plus One
- [LeetCode]66. Plus One
- Java-Excel报表开发POI(含POI保护工作表功能)
- PowerShellGet系列(一):PowerShell的最佳管理能手
- Python *args *kwargs
- 第三章 JavaScript 变量、数据类型、对象
- 【Spring】
- 66. Plus One
- 移动端两端对齐支持iPhone6
- Java备忘录模式
- django使用redis问题
- swift3.0 避免循环引用
- poj 1275--Cashier Employment【差分约束系统】
- 控件设置alpha或者layer的opacity时,他的子类的透明度也会跟着变成透明
- 二分算法
- Lua与C的交互(1)