-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrionic_Array_637.py
More file actions
37 lines (33 loc) · 958 Bytes
/
Copy pathTrionic_Array_637.py
File metadata and controls
37 lines (33 loc) · 958 Bytes
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
class Solution(object):
def isTrionic(self, nums):
n = len(nums)
if n < 3:
return False
p = -1
for i in range(n - 1):
if nums[i] > nums[i + 1]:
p = i
break
if p <= 0:
return False
q = -1
for i in range(p, n - 1):
if nums[i] < nums[i + 1]:
q = i
break
if q <= p or q >= n - 1:
return False
def inc(arr, s, e):
for i in range(s + 1, e + 1):
if arr[i] <= arr[i - 1]:
return False
return True
def dec(arr, s, e):
for i in range(s + 1, e + 1):
if arr[i] >= arr[i - 1]:
return False
return True
if (inc(nums, 0, p) and dec(nums, p, q) and inc(nums, q, n - 1)):
return True
else:
return False