public class Solution {
public int[] PlusOne(int[] digits) {
var last = digits[digits.Length - ]; if (last + < )
{
digits[digits.Length - ]++;
return digits;
}
else
{
var list = new List<int>();
int step = ;
for (int i = digits.Length - ; i >= ; i--)
{
var cur = digits[i];
cur = cur + step;
if (cur >= )
{
step = ;
}
else
{
step = ;
} list.Add(cur % );//原来肯定是9,9+1变为10
} if (step == )
{
list.Add();
}
list.Reverse();
return list.ToArray();
}
}
}

https://leetcode.com/problems/plus-one/#/description

补充一个python的实现:

 class Solution:
def plusOne(self, digits: List[int]) -> List[int]:
n = len(digits)
temp = [] * n
up =
last = digits[-]
last +=
if last == :
temp[-] =
up =
else:
temp[-] = last for i in range(n-,-,-):
cur = digits[i]
cur += up
if cur == :
temp[i] =
up =
else:
temp[i] = cur
up =
if up == :
temp.insert(,)
return temp
05-11 20:03