66. Plus One
来源:互联网 发布:郑爽 不吃饭知乎 编辑:程序博客网 时间:2024/06/11 05:17
原题
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.
代码实现
public int[] PlusOne(int[] digits) { int index = digits.Length - 1; if(digits[index]<9) { digits[index]++; return digits; } if(index==0) return new int[]{1,0}; int i = index; while(digits[i]==9) { digits[i] = 0; //位溢出 if(i==0) //所有的位溢出 { int [] rtn = new int[index+2]; rtn[0]=1; return rtn; } i--; } digits[i]++; //第i位不为9(i > 0) return digits; }
2 0
- [LeetCode]66.Plus One
- LeetCode --- 66. Plus One
- [Leetcode] 66. Plus One
- [leetcode] 66.Plus One
- 66. Plus One
- 66. Plus One
- [leetcode] 66. Plus One
- Leetcode-66. Plus One
- 【leetcode】66. Plus One
- 66. Plus One
- 66. Plus One LeetCode
- 66. Plus One
- 66. Plus One
- 66. Plus One
- 66. Plus One
- 66. Plus One
- 【LeetCode】66. Plus One
- [LeetCode]66. Plus One
- 最少拦截系统
- 2017阿里后台开发工程师面试经验分享之一面
- [LeetCode] Counting Bits 计算二进制表示法中1的位数
- 我的java学习路之I/O流学习应用查找文件
- 使用python链接wamp或者xamp中的数据库
- 66. Plus One
- Android Studio 的SDK Manager
- python语法小知识
- Sublime Text 3 快捷键
- BootStrap学习笔记(二):关于分页组件中<a>标签disable后还是可以点击的问题
- Balanced Binary Tree
- AndroidN 中vulkan 的支持
- 百度移动搜索优化指南2.0
- LeetCode刷题(C++)——Median of Two Sorted Arrays(Hard)