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 l=digits.length;
int ite=l-1;
while(ite>=0){
if(digits[ite]==9){
digits[ite]=0;
ite--;
}else{
digits[ite]++;
return digits;
}
}
int[] digits2= new int[l+1];
if(ite==-1){
digits2[0]=1;
for(int i=1;i<l+1;i++){
digits2[i]=digits[i-1];
}
}
return digits2;
}
}