Skip to content

Commit d60c4f3

Browse files
authored
Merge pull request #2386 from younessZMZ/main
Create 0665-non-decreasing-array.py
2 parents 4c7749d + da299b5 commit d60c4f3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

python/0665-non-decreasing-array.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
def checkPossibility(self, nums):
3+
if len(nums) <= 2:
4+
return True
5+
changed = False
6+
for i, num in enumerate(nums):
7+
if i == len(nums) - 1 or num <= nums[i + 1]:
8+
continue
9+
if changed:
10+
return False
11+
if i == 0 or nums[i + 1] >= nums[i - 1]:
12+
nums[i] = nums[i + 1]
13+
else:
14+
nums[i + 1] = nums[i]
15+
changed = True
16+
return True

0 commit comments

Comments
 (0)