-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonotonic_array.py
More file actions
39 lines (39 loc) · 1 KB
/
Copy pathmonotonic_array.py
File metadata and controls
39 lines (39 loc) · 1 KB
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
34
35
36
37
38
39
class Solution:
def isMonotonic(self, nums: List[int]) -> bool:
if len(nums) == 1:
return True
x = nums[0]
y = nums[1]
x1 = x < y
x2 = x > y
temp1 = temp2 = None
if x1:
for i in nums:
if x <= i:
x = i
else:
return False
elif x2:
for i in nums:
if x >= i:
x = i
else:
return False
else:
for i in nums:
if temp1 == False:
break
if x <= i:
x = i
else:
temp1 = False
for i in nums:
if temp2 == False:
break
if x >= i:
x = i
else:
temp2 = False
if temp1 == False and temp2 == False:
return False
return True