Created
May 4, 2021 13:08
-
-
Save vrat28/ff4acd7668463f2239d40708ceca76c8 to your computer and use it in GitHub Desktop.
Count 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 { | |
func checkPossibility(_ nums: [Int]) -> Bool { | |
var count = 0 | |
var nums = nums | |
for i in 1..<nums.count { | |
if nums[i] < nums[i - 1] { | |
if i == 1 || nums[i - 2] <= nums[i] { | |
nums[i - 1] = nums[i] | |
count += 1 | |
} | |
else{ | |
nums[i] = nums[i - 1] | |
count += 1 | |
} | |
} | |
} | |
return count <= 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment