leetcode 66: Plus One
2015-08-03 13:38
357 查看
class Solution { public: vector<int> plusOne(vector<int>& digits) { reverse(digits.begin(),digits.end()); int carry=1; for(int i=0;i<digits.size();i++) { int temp=digits[i]+carry; if(temp==10) { digits[i]=0; carry=1; } else { digits[i]=temp; carry=0; } } if(carry==1) digits.push_back(1); reverse(digits.begin(),digits.end()); return digits; } };
相关文章推荐
- Bus System
- Scikit-Learn:开源的机器学习Python模块
- poj 3041 构图+最小点覆盖
- maven 在 mac中的配置
- Linux下快速安装Mysql及使用
- 网络路由设计基础
- git笔记
- C++读取mat文件 & VS2010 环境配置
- Linux C 堆与栈的区别
- 【Unity 教程】对象池
- HNU Knockout Racing
- fatal error LNK1140临时解决方案
- HNU Knockout Racing
- 修改virtualbox的UUID,使virtualbox的虚拟磁盘可以复制
- 给JSP页面添加验证码
- 黑马程序员——java基础_继承、抽象类、接口、多态
- 设计模式 工厂方法模式
- 暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns
- Bootstrap的表单
- mysql 导出excel