Plus One
2015-06-16 23:44
218 查看
Description:
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.
Code:
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.
Code:
vector<int> plusOne(vector<int>& digits) { vector<int>result(digits); bool flag = true; int index = result.size()-1; while ( index >= 0 ) { result[index] = (result[index]+1)%10; flag = (result[index--]==0)?true:false; if (!flag) return result; } if (flag) { result.insert(result.begin(),1); } return result; }
相关文章推荐
- php Hash函数了解
- vim方向键乱码
- 2015最流行的android组件、工具、框架大全
- javascript 获取调用属性的对象
- NodeJS框架express的途径映射(路由)功能及控制
- CentOS下如何完全卸载MySQL?解决卸载不干净的问题
- Android中如何查看内存
- 问题安装完hadoop后无法连接dfs
- Andriod网络优化相关技术点整理
- CentOS 7 之Helloworld with c
- ORA-01123:无法启动联机备份;未启用介质恢复.
- Struts2入门2
- Maven + Nexus + SVN + Eclipse 配置步骤说明
- Sokcet编程常用函数
- Android中AsyncTask的分析和使用
- UIButton的一些基本用法
- LeetCode——Contains Duplicate II
- python 爬虫
- PHP 发送HTTP请求
- 二十三