Short Concise JAVA AC Solution


  • 0
    W
        public boolean checkPossibility(int[] nums) {
            boolean changed = false;
            for (int i = 1; i < nums.length; i++) {
                if (nums[i] < nums[i - 1]) {
                    if (!changed) {
                        if (i - 2 < 0 || nums[i] >= nums[i - 2]) {
                            nums[i - 1] = nums[i];
                        } else {
                            nums[i] = nums[i - 1];
                        }
                        changed = true;
                    } else {
                        return false;
                    }
                }
            }
            return true;
        }
    

Log in to reply
 

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