Non-decreasing Array


  • 0
    C
    class Solution {
        public boolean checkPossibility(int[] nums) {
    int l = nums.length,t=0,x=0;
            for (int i=1;i<l;i++){
                if (nums[i-1]> nums[i]){
                    t++;
                    x=i;
                }
            }
            if (t>1) return false;
            if (t==0) return true;
            if (x == 1) return true;
            if (x== l-1) return true;
            return (nums[x-2] <= nums[x] || nums[x-1]<=nums[x+1]);
    }
    }
    

Log in to reply
 

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