# leetcode 66. Plus One

### 题目

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.

### 解

public class Solution {
public int[] plusOne(int[] digits) {

int j=digits.length-1;
digits[j]+=1;
while(j>0){
if(digits[j]>9){
digits[j]=digits[j]-10;
digits[j-1]+=1;
}

j--;
}

if(digits[0]<10){
return digits;
}else
{
int carry=0;
if(digits[0]>9){
digits[0]=digits[0]-10;
carry=1;
}
int[] ret=new int[digits.length+1];
ret[0]=carry;
for(int i=1;i<ret.length;i++){
ret[i]=digits[i-1];
}
return ret;

}

}
}

#### LeetCode 66 — Plus One（C++ Java Python）

2014-04-02 08:53:48

#### LeetCode --- 66. Plus One

2015-03-19 21:53:21

#### LeetCode（66）Plus One

2015-08-18 15:38:10

#### LeetCode OJ 系列之66 Plus One --Python

2015-12-09 01:32:51

#### 【leetcode】66. Plus One【java】

2016-12-17 15:43:36

#### [leetcode]Plus One C语言

2015-08-27 15:23:14

#### Plus One python 题解

2015-04-23 20:15:08

#### leetcode66题 题解 翻译 C语言版 Python版

2016-04-15 10:45:59

#### leetcode解题之66 # Plus One Java版

2017-03-13 09:30:20

#### Leetcode 66. Plus One 加一！ 解题报告

2016-05-08 23:48:09