Skip to content

Instantly share code, notes, and snippets.

@vrat28
Created May 4, 2021 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vrat28/ff4acd7668463f2239d40708ceca76c8 to your computer and use it in GitHub Desktop.
Save vrat28/ff4acd7668463f2239d40708ceca76c8 to your computer and use it in GitHub Desktop.
Count Possibility
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