标签:style nbsp new lse col solution for 覆盖 its
1 class Solution { 2 public int[] plusOne(int[] digits) { 3 int n = digits.length; 4 int[] res = new int[n+1]; 5 int carry = 0; 6 for(int i = n - 1; i >= 0; i--) { 7 if(i == n - 1) { 8 carry = (digits[i]+1) / 10; //digits 会被覆盖 所以先记录carry 9 digits[i] = (digits[i]+1) % 10; 10 11 }else { 12 int tmp = digits[i]; //digits 会被覆盖 所以先记录 13 digits[i] = (digits[i]+carry) % 10; 14 carry = (tmp+carry) / 10; 15 } 16 17 if(i == 0 && carry == 1) { 18 res[0] = 1; 19 for(int j = 1; j < n+1; j++) { 20 res[j] = digits[j-1]; 21 } 22 return res; 23 } 24 } 25 return digits; 26 } 27 }
标签:style nbsp new lse col solution for 覆盖 its
原文地址:https://www.cnblogs.com/goPanama/p/9639716.html