My Java Solution 0ms


  • 0
    F
    public class Solution {
        public int[] plusOne(int[] digits){
            boolean flag = false;
            int len = digits.length;
            while(flag = !flag && len > 0){
                if(digits[len - 1] != 9){
                    digits[len - 1]++;
                }else{
                    digits[len - 1] = 0;
                    flag = false;
                }
                len--;
            }
    
            int[] res;
            if(digits[0] == 0){
                res = new int[digits.length + 1];
                res[0] = 1;
                System.arraycopy(digits, 0, res, 1, len);
            }else res = digits;
            return res;
        }
    }
    

Log in to reply
 

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