Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def checkPossibility(self, nums: List[int]) -> bool:
- cnt = 0
- if len(nums) <= 1: return True
- for i in range(1, len(nums)):
- if nums[i-1] > nums[i]:
- if cnt > 0 or 1 < i < len(nums)-1 and nums[i-2] > nums[i] and nums[i+1] < nums[i-1]:
- return False
- cnt += 1
- return True
- # -2 -1 i +1
- # 7 10 5 -> can't decrease i-1 nums[i-2] > nums[i]
- # 7 10 5 3 -> can't increase i+1 nums[i+1] < nums[i-1]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement