Skip to content

Commit

Permalink
Create 0665-non-decreasing-array.py
Browse files Browse the repository at this point in the history
  • Loading branch information
younessZMZ committed Apr 1, 2023
1 parent 3317bf9 commit da299b5
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions python/0665-non-decreasing-array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution:
def checkPossibility(self, nums):
if len(nums) <= 2:
return True
changed = False
for i, num in enumerate(nums):
if i == len(nums) - 1 or num <= nums[i + 1]:
continue
if changed:
return False
if i == 0 or nums[i + 1] >= nums[i - 1]:
nums[i] = nums[i + 1]
else:
nums[i + 1] = nums[i]
changed = True
return True

0 comments on commit da299b5

Please sign in to comment.