Plus One
2015-12-07 10:53
351 查看
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.
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) { int q = 1; for(int i=digits.size()-1;i>=0;i--){ int temp = (digits[i]+q)/10; digits[i] = (digits[i]+q)%10; q = temp; } if(q == 0){ return digits; }else{ vector<int> result(digits.size()+1); result[0] = q; for(int i=1;i<result.size();i++){ result[i] = digits[i-1]; } return result; } } };
相关文章推荐
- 谈论HashMap,HashSet,HashTableeasy被我们忽视
- IUT225 Energy Data Management_Col62.pdf
- URI和URL的区别
- 视频编解码的资料收集(1)
- 谈C++内存管理与智能指针
- OpenCV中将MAT类型的对象作为InputArray类型的对像传递给函数
- selenium webdriver python 操作Chrome浏览器
- SQL Server中bit数据类型应用
- Hello Android - 调用打电话和发短信及intent一些其他用法
- msm8996的gpio和irq
- runloop介绍
- Android版本和API Level对应关系
- 为Android硬件抽象层(HAL)模块编写JNI方法提供Java访问硬件服务接口
- [国嵌攻略][069][Bootm命令移植]
- [转]JDBC中日期时间的处理技巧
- 字节流、字符串、16进制字符串转换
- pl/sql_6_例外
- stm32正交编码器问题
- lspci和ethtool
- Object.defineProperty