leetcode刷题,总结,记录,备忘66
来源:互联网 发布:python冷门知识 编辑:程序博客网 时间:2024/06/06 08:39
leetcode66Plus One
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.
从尾巴开始找,加1,满10就进1,还是比较容易的。class Solution {public: vector<int> plusOne(vector<int>& digits) { for (int i = digits.size()-1; i >= 0; --i) { if (i == digits.size()-1 && digits[i] == 9) { digits[i] = 0; continue; } else if (i == digits.size()-1 && digits[i] != 9) { digits[i] += 1; break; } if (digits[i] == 9) { digits[i] = 0; continue; } else { digits[i] += 1; break; } } vector<int> temp; temp.push_back(1); if (digits[0] == 0) { temp.insert(temp.end(), digits.begin(), digits.end()); return temp; } else { return digits; } }};
0 0
- leetcode刷题,总结,记录,备忘66
- leetcode刷题。总结,记录,备忘 104
- leetcode刷题。总结,记录,备忘 100
- leetcode刷题。总结,记录,备忘 191
- leetcode刷题。总结,记录,备忘。168
- leetcode刷题, 总结,记录,备忘 171
- leetcode刷题 ,总结,记录,备忘。144
- leetcode刷题,总结,记录, 备忘 141
- leetcode刷题,总结,记录,备忘。116
- leetcode刷题,总结,记录,备忘。96
- leetcode刷题。记录,总结,备忘。217
- leetcode 刷题, 总结,记录,备忘 35
- leetcode刷题,总结,记录,备忘 226
- leetcode刷题,总结,记录,备忘 169
- leetcode刷题,总结,记录,备忘137
- leetcode刷题,总结,记录,备忘83
- leetcode刷题,总结,记录,备忘70
- leetcode刷题,总结,记录,备忘 108
- iPhone开发之沙盒路径的获取
- 4.7 蚂蚁爬杆问题
- 关于activity
- SweetAlert-js应用
- Android 绘图进阶(四):自定义View属性(灰常重要)
- leetcode刷题,总结,记录,备忘66
- clone graph
- Python的输入和raw_input()内建函数等以及相关运算符
- JSP九大内置对象
- 无法掌握也不要尝试掌握
- 【炫技帖】模拟用户中心下拉时背景放大效果
- POJ 3461.Oulipo(KMP)
- 0918知识点总结
- C++之多态性与虚函数