-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.py
33 lines (28 loc) · 870 Bytes
/
solution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Solution(object):
def checkPossibility(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
parts = []
part = []
for i in range(len(nums)):
part.append(nums[i])
if i + 1 < len(nums) and nums[i + 1] < nums[i]:
parts.append(part)
part = []
if len(part) > 0:
parts.append(part)
if len(parts) <= 1:
return True
elif len(parts) == 2:
left = parts[0]
right = parts[1]
if len(left) == 1 or len(right) == 1:
return True
elif right[1] >= left[-1] or right[0] >= left[-2]:
return True
else:
return False
else:
return False