标签:tom dig 问题 tty number turn title git its
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 class Solution {
public int[] PlusOne(int[] digits) {
int plus = 1;
List<int> resultList = new List<int>();
for (int i = digits.Length - 1; i >= 0; i--) {
if (plus > 0) {
digits[i] += 1;
if (digits[i] >= 10) {
digits[i] = digits[i] % 10;
} else {
plus--;
}
}
resultList.Add(digits[i]);
if (i == 0 && plus == 1) {
resultList.Add(1);
}
}
resultList.Reverse();
return resultList.ToArray();
}
}
标签:tom dig 问题 tty number turn title git its
原文地址:http://www.cnblogs.com/xiejunzhao/p/d33f14cb837d4f624b1e6004cc99ec6a.html