AC Java Solution


  • 0
    C
        public int[] plusOne(int[] digits) {
            int cur = digits.length - 1;
            while(cur > -1){
                digits[cur]++;
                if(digits[cur] == 10){
                    digits[cur] = 0;
                    cur--;
                }else{
                    break;
                }
            }
            
            if(cur == -1){
                int[] ans = new int[digits.length + 1];
                ans[0] = 1;
                for(int i  = 0; i < digits.length; i++){
                    ans[i + 1] = digits[i];
                }
                return ans;
            }else{
                return digits;
            }
           
    
    
        }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.