Plus One
来源:互联网 发布:图标软件下载 编辑:程序博客网 时间:2024/04/28 01:14
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.
需要记录当前的仅为carry,而且别忘了要+1
class Solution {public: vector<int> plusOne(vector<int> &digits) { int carry = 0; int pos = digits.size() - 1; digits[pos] += 1; for( ; pos >= 0; --pos){ int tmp = carry;//需要记录下 carry = ( carry + digits[pos]) / 10; digits[pos] = (digits[pos] + tmp) % 10; } if( carry != 0) digits.insert( digits.begin(), carry); 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
- OpenCV学习笔记3 OpenCV核心模块与核心功能Core Module & Core Functionality(二)
- centos6.5常见命令及其作用
- Linux mmap概要解释
- Ubuntu的网络配置
- Linux基础
- Plus One
- HttpClient实现文件的上传下载
- 会场安排问题
- 如何同步视频
- STL在服务器中的问题
- 计算斐波纳契数,分析算法复杂度
- Best Time to Buy and Sell Stock II
- 与屏幕亮度调节相关的各种方法整理
- 关联容器 map