Created
May 4, 2021 13:13
-
-
Save vrat28/c67aa68f904139e53b7fd26d178a81f1 to your computer and use it in GitHub Desktop.
Check Possibility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public boolean checkPossibility(int[] nums) { | |
int count = 0; | |
for (int i=1; i<nums.length;i++){ | |
if (nums[i]<nums[i-1]){ | |
if(i == 1 || nums[i-2] <= nums[i]) { | |
nums[i-1] = nums[i]; | |
} | |
else{ | |
nums[i] = nums[i-1]; | |
} | |
count++; | |
} | |
} | |
return count < 2; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment