Simple Java Solution


  • 1
    S
    class Solution {
        public boolean checkPossibility(int[] nums) {
            boolean modifiedOne=false;
            
            for(int i=0;i<nums.length-1;i++){
                if(nums[i]>nums[i+1]){
                    if(modifiedOne) return false;
                    if((i==0||nums[i-1]<=nums[i+1])||((i+1)==nums.length-1||nums[i]<=nums[i+2])){
                        modifiedOne=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.