-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3637. Trionic Array I
More file actions
48 lines (48 loc) · 1.46 KB
/
3637. Trionic Array I
File metadata and controls
48 lines (48 loc) · 1.46 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
40
41
42
43
44
45
46
47
48
class Solution(object):
def isTrionic(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
index = 0
ln = len(nums)
if ln < 4:
return False
#if ln == 4 and nums[1] < nums[2]:
# return False
sec1 = 1
sec2 = 0
sec3 = 0
ln1 = ln - 1
if nums[1] < nums[0] or nums[-1] < nums[-2]:
#if nums[1] < nums[0]:
return False
while index < ln1:
if sec1 == 1:
if nums[index] < nums[index+1]:
index += 1
#elif nums[index] > nums[index+1] and nums[index-1] < nums[index]:
elif nums[index] > nums[index+1]:
sec1 = 0
sec2 = 1
index += 1
else:
return False
elif sec2 == 1:
if nums[index] > nums[index+1]:
index += 1
#elif nums[index] < nums[index+1] and nums[index-1] > nums[index]:
elif nums[index] < nums[index+1]:
sec2 = 0
sec3 = 1
index += 1
else:
return False
elif sec3 == 1:
if nums[index] < nums[index+1]:
index += 1
else:
return False
if sec1 == 1 or sec2 == 1:
return False
return True