Leetcode:66. Plus One(JAVA)
来源:互联网 发布:qq飞车改装30雷诺数据 编辑:程序博客网 时间:2024/06/08 08:35
【问题描述】
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.
【思路】实质是用数组实现了大数加法,从最后一位加1开始,设置进位,如到数组头时仍有进位则将数组按位后移,0位补上进位。
public class Solution { public int[] plusOne(int[] digits) { int c = 1;for (int i = digits.length - 1; i >= 0; i--) {int temp = digits[i] + c;c = temp / 10;digits[i] = temp % 10;}if (c > 0) {int[] array = new int[digits.length + 1];array[0] = c;for (int i = 1; i < array.length; i++) {array[i] = digits[i - 1];}return array;} else {return digits;} }}
0 0
- Leetcode:66. Plus One(JAVA)
- (Java)LeetCode-66. Plus One
- 【leetcode】66. Plus One【java】
- [LeetCode] 66. Plus One java
- [leetcode]66. Plus One(Java)
- [Leetcode] Plus One (Java)
- [LeetCode][Java] 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
- 66. Plus One LeetCode
- 【LeetCode】66. Plus One
- [LeetCode]66. Plus One
- 【LeetCode】66. Plus One
- 深入理解Java 虚拟机(周志明)笔记(四)——Java对象创建过程
- Logstash中配置默认索引映射(_default_属性)
- 深入分析 Java 中的中文编码问题
- java thread join
- OSI七层模型详解(物理层、数据链路层、网络层、传输层.....应用层协议与硬件)
- Leetcode:66. Plus One(JAVA)
- Python基础--快速改造:基础知识
- 杭电1228
- Codeforces Round #345 (Div. 2) B. Beautiful Paintings
- VS2010产生C的dll方法和C#调用方式
- HDU 1005 Number Sequence (找循环节)
- 一个经典例子让你彻彻底底理解java回调机制
- 八皇后问题(回溯法)
- iOS开发技巧:设置状态样式