Plus One leetcode
2016-01-07 20:19
260 查看
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.
Subscribe to see which companies asked this question
The digits are stored such that the most significant digit is at the head of the list.
Subscribe to see which companies asked this question
vector<int> plusOne(vector<int>& digits) { int add = 1; int size = digits.size(); while (size-- && add > 0) { int num = digits[size] + add; add = num / 10; digits[size] = num % 10; } if (add > 0) digits.insert(digits.begin(), add); return digits; }
相关文章推荐
- Jquery自定义一个带名称的、可以传参数的函数以及setTimeout延迟调用,用法详解
- 求int型数据在内存中存储时1的个数
- cf#336-B-Hamming Distance Sum
- 安卓核心六Intent对象
- 店小二的总结
- Java多线程-实现多线程的两种方式
- php7新特性
- 安卓核心五application组件
- Coreball的小游戏
- Linux zip命令
- 人体美化的一些处理图像处理
- 动态规划-寻找最优分配时间。(未理解)
- IO_其他流_基本数据类型+String处理流JAVA158
- Oracl 动态执行表不可访问,本会话的自动统计被禁止
- 手机app测试分析方法 -- 进阶方法
- 安卓核心组件四BroadCastReceiver
- 冒泡排序
- UISearchBar协议常用方法
- 外卖平台乱象迭出!究竟谁该负责?
- ambari高级操作