leetcode 66. Plus One
来源:互联网 发布:新网域名转出申请 编辑:程序博客网 时间:2024/06/07 16:14
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.
You may assume the integer do not contain any leading zero, except the number 0 itself.
The digits are stored such that the most significant digit is at the head of the list.
You may assume the integer do not contain any leading zero, except the number 0 itself.
The digits are stored such that the most significant digit is at the head of the list.
题目:一个整数按照每一位存在数组里面,然后返回整数 + 1之后的数组
所以:一位一位处理,不全部提出来
class Solution {public: vector<int> plusOne(vector<int>& dig) { int flag = 0; int pos = dig.size(); while ( (--pos) >= 0 ) { if (pos == dig.size() - 1) { if (dig[pos] < 9) { dig[pos]++; return dig; } else { dig[pos] = 0; flag = 1; } } else { if (dig[pos] + flag < 10) { dig[pos]++; return dig; } else dig[pos] = 0; } } if (flag==1) { dig.insert(dig.begin(), 1); } return dig; }};
阅读全文
0 0
- [LeetCode]66.Plus One
- LeetCode --- 66. Plus One
- [Leetcode] 66. Plus One
- [leetcode] 66.Plus One
- [leetcode] 66. Plus One
- Leetcode-66. Plus One
- 【leetcode】66. Plus One
- 66. Plus One LeetCode
- 【LeetCode】66. Plus One
- [LeetCode]66. Plus One
- 【LeetCode】66. Plus One
- LeetCode 66. Plus One
- LeetCode *** 66. Plus One
- leetcode 66. Plus One
- 【leetcode】66. Plus One
- leetcode 66. Plus One
- [LeetCode]66. Plus One
- Leetcode 66. Plus One
- idtcpserver 多线程同步问题
- android:怎么在Listview里面加载网络图片?或者在背景中加载网络图片?类似评论列表的头像等
- Android手机收集app异常保存到本地
- Vue-cli搭建项目遇到的问题
- json 的各种解析形式
- leetcode 66. Plus One
- oracle定时器实用代码
- @Transactional用法
- 第九周 项目一 二叉树算法库
- Freescle MSCAN滤波器配置方法VBA基础入门实现
- Log4Net的使用之winform
- 第九周项目二
- 最大熵模型
- 解决ssh无法远程连接到NAT模式的虚拟机的问题