-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path334. Increasing Triplet Subsequence(by James, Kuan)
More file actions
50 lines (44 loc) · 1.22 KB
/
334. Increasing Triplet Subsequence(by James, Kuan)
File metadata and controls
50 lines (44 loc) · 1.22 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
49
50
class Solution(object):
def increasingTriplet(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
i=0
count=0
top=[]
buttom=[]
while i < len(nums)-1:
if nums[i] - nums[i+1] < 0:
count += 1
top.append(nums[i+1])
buttom.append(nums[i])
i+=1
# print(i)
# print(top,count)
j = 0
k = 0
if count >= 2:
while j < len(top)-1:
if top[j] - top[j+1] < 0:
return True
j += 1
while k < len(buttom)-1:
if buttom[k] - buttom[k+1] < 0:
return True
k += 1
return False
# curMax=0
# count=0
# for i in range(len(nums)-1):
# if nums[i+1]-nums[i]>0:
# tmp=max(nums[i+1],nums[i])
# if tmp>curMax:
# curMax=tmp
# count+=1
# else:
# continue
# if count>=2:
# return True
# else:
# return False