my java O(n) solution 26 ms


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

Log in to reply
 

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