-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrictly_increasing_or_strictly_decreasing.py
69 lines (43 loc) · 1.33 KB
/
strictly_increasing_or_strictly_decreasing.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#Given a list of integers nums, return whether the list is strictly increasing or strictly decreasing.
class Solution:
def solve(self, nums):
if len(nums) < 2:
return True
if nums[0] == nums[1]:
return False
if nums[0] < nums[1]:
increasing = True
for i in range(len(nums)-1):
if nums[i] >= nums[i+1]:
return False
return True
else:
increasing = False
for i in range(len(nums)-1):
if nums[i] <= nums[i+1]:
return False
return True
#another
class Solution:
def solve(self, nums):
for i in range(1, len(nums)):
if nums[i - 1] >= nums[i]:
break
else:
return True
for i in range(1, len(nums)):
if nums[i - 1] <= nums[i]:
break
else:
return True
return False
#another
class Solution:
def solve(self, nums):
if len(nums) == 1:
return True
desc = nums[0] > nums[1]
for i in range(0, len(nums) - 1):
if (desc and nums[i] <= nums[i + 1]) or (not desc and nums[i] >= nums[i + 1]):
return False
return True