-
Notifications
You must be signed in to change notification settings - Fork 0
/
1964.py
119 lines (92 loc) · 6.23 KB
/
1964.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
class Solution(object):
def longestObstacleCourseAtEachPosition(self, obstacles):
"""
:type obstacles: List[int]
:rtype: List[int]
"""
def find_longest(obcc):
def LIS_selelct(inter_list, i):
select = []
for x in inter_list:
if x >= i:
select.append(True)
else:
select.append(False)
return select
# deepcopy = [i for i in obc]
# for i in deepcopy:
# if i > obc[-1]:
# obc.remove(i)
obc=[]
for i in obcc:
if i <=obcc[-1]:
obc.append(i)
obc.reverse()
LIS = [1]
for index, i in enumerate(obc[1:]):
# print(index,i)
inter_list = obc[:index + 1]
# print(i, inter_list, )
# x=list(map(lambda x: True if x <= i else False,inter_list))
select = LIS_selelct(inter_list, i)
x = list(map(lambda a, b: a * b, LIS, select))
LIS.append(max(1, 1 + max(x)))
# print(select)
# print(LIS)
# print(x)
# map(lambda a,b:a*b,
return max(LIS)
ans=[]
for i in range(1,len(obstacles)+1):
ans.append(find_longest(obstacles[:i]))
# print(obstacles[:i])
return ans
def find_longest(self,obc):
def LIS_selelct(inter_list,i):
select=[]
for x in inter_list:
if x >=i:
select.append(True)
else:
select.append(False)
return select
for i in obc.copy():
if i > obc[-1]:
obc.remove(i)
obc.reverse()
LIS=[1]
for index,i in enumerate(obc[1:]) :
# print(index,i)
inter_list= obc[:index+1]
print(i,inter_list,)
# x=list(map(lambda x: True if x <= i else False,inter_list))
select=LIS_selelct(inter_list,i)
x=list(map(lambda a,b:a*b,LIS,select))
LIS.append(max(1,1+max(x)))
print(select)
print(LIS)
# print(x)
# map(lambda a,b:a*b,
return max(LIS)
# %%
obstacles =[76,89,79,135,108,146,89,70,180,160,120,2,30,75,8,151,96,73,181,88,155,9,7,29,186,164,180,97,8,5,166,35,75,124,12,94,133,110,193,176,124,69,185,68,51,100,174,189,66,35,134,71,55,196,70,156,36,107,1,62,39,192,60,26,194,103,145,181,79,62,126,122,127,7,100,11,77,143,30,163,138,62,81,26,90,97,163,187,161,36,64,100,55,79,21,36,132,58,163,118,150,122,190,114,21,185,48,148,110,18,94,113,164,46,144,192,4,168,145,125,56,54,193,148,75,122,49,95,7,113,36,23,157,117,194,186,121,14,37,121,191,151,136,193,172,133,184,123,15,94,17,174,26,166,64,84,118,155,199,56,15,111,66,5,174,95,178,96,198,82,9,94,200,133,123,128,125,182,10,99,195,158,18,26,13,103,166,169,93,88,83,77,54,163,188,63,194,55,174,17,83,161,194,68,28,75,160,159,41,124,140,197,28,67,135,80,126,114,56,164,90,4,76,67,33,51,139,82,149,200,42,175,97,64,161,113,129,104,193,81,94,167,74,25,61,90,55,125,12,52,129,148,128,52,156,15,24,5,42,20,39,177,62,69,151,26,187,93,146,78,109,89,89,109,107,177,73,147,197,16,187,13,29,152,161,189,112,106,160,194,199,159,173,182,157,184,174,199,42,80,195,28,8,177,154,178,109,19,77,165,139,145,21,119,91,178,139,22,20,133,11,104,63,181,29,76,94,98,135,84,130,57,185,199,89,83,123,31,10,5,33,38,104,18,180,116,134,52,125,191,132,45,174,117,85,94,162,133,57,67,167,112,103,137,161,134,199,79,198,197,172,178,148,59,4,78,145,162,190,198,25,115,151,174,60,149,69,36,133,116,59,96,146,89,133,178,63,181,41,57,165,90,33,123,42,22,95,133,85,64,16,152,22,65,123,168,104,22,22,44,151,17,68,86,81,131,154,94,59,95,126,135,160,21,136,127,87,58,109,52,177,168,45,54,142,173,174,22,91,193,105,135,163,13,123,160,187,162,75,119,19,156,57,22,92,2,52,112,23,13,17,137,54,160,155,61,194,99,17,53,98,43,97,125,64,145,194,180,107,141,181,178,68,187,161,62,66,73,185,68,110,88,115,21,13,89,33,176,3,123,88,49,150,27,126,82,34,144,127,140,131,187,132,57,12,132,51,66,123,70,137,194,70,126,109,38,4,189,50,190,195,126,167,161,157,185,81,43,121,176,26,17,121,138,176,174,5,60,17,122,149,138,10,46,181,63,30,57,47,4,149,69,114,108,184,26,108,7,125,169,199,103,5,12,18,132,143,43,184,33,91,153,188,54,178,104,41,164,174,37,199,133,172,71,29,173,49,84,159,31,40,46,18,17,67,125,159,37,101,102,44,90,106,132,8,57,97,117,157,113,17,161,181,52,44,200,90,128,158,32,54,167,174,31,174,135,186,133,10,20,124,136,47,181,5,165,74,85,73,108,96,39,68,55,10,37,98,30,65,34,184,130,85,178,47,1,67,114,197,23,29,60,60,149,18,100,4,25,115,42,76,90,179,106,51,103,136,12,13,126,128,136,63,2,131,101,174,61,138,21,2,185,6,181,101,99,143,112,10,32,101,15,132,63,31,70,51,155,184,1,35,139,101,24,29,198,170,30,173,125,193,112,145,161,75,59,37,162,123,36,52,200,161,133,1,169,179,176,69,198,63,69,64,42,121,97,124,64,29,95,29,124,124,73,124,104,44,180,30,149,30,190,79,136,40,1,19,144,62,163,174,195,98,118,40,110,15,60,177,102,28,167,90,103,40,104,155,168,196,165,190,139,185,97,76,158,134,182,35,31,133,168,118,120,74,176,71,138,200,199,140,41,160,147,198,139,185,182,42,182,141,112,18,16,152,17,113,92,158,71,82,30,127,66,53,172,35,182,10,106,100,78,51,174,162,96,105,112,176,174,141,41,131,87,118,188,19,131,136,78,23,172,195,179,152,29,149,16,1,106,143,122,55,180,41,74,154,95,171,50,139,21,55,26,25,72,75,65,144,174,102,92,37,56,114,83,11,5,178,87,46,62,127,139,61,126,72,198,168,50,64,61,150,73,117,5,145,138,165,53,58,21,63,124,91,79,156,20,142,146,122,62,4,116,31,39,110,133,179,17,148,122,87,39,198,51,103,62,130,106,102,17,151,68,3,32,52,79,169,159,51,22,20,123,49,167,43,84,102,106,136,83,187,184,93,69,123,21,45,136]
x = Solution
Solution.longestObstacleCourseAtEachPosition(x, obstacles)
# Solution.find_longest(x, obstacles)
#%%
a=[1,2,3]
x=map(lambda x: True if x>2 else False,a)
print(sum(x))
#%%
False*5
#%%
a=[1]
x=list(map(lambda x: True if x >1 else False,a))
# x=list(map(lambda a,b: a+b,a,b))
#%%
obstacles=[5,1,5,5,1,3,4,5,1,4]
deepcopy = [i for i in obstacles]
for i in deepcopy:
if i > obstacles[-1]:
obstacles.remove(i)
print(obstacles)