FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-Solutions/Python/132-pattern.py at master · cppp/LeetCode-Solutions · GitHub
cppp
LeetCode-Solutions
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
LeetCode-Solutions
/
Python
/
132-pattern.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
37 lines (34 loc) · 903 Bytes
Breadcrumbs
LeetCode-Solutions
/
Python
/
132-pattern.py
Copy path
File metadata and controls
37 lines (34 loc) · 903 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
# Time: O(n)
# Space: O(n)
class
Solution
(
object
):
def
find132pattern
(
self
,
nums
):
"""
:type nums: List[int]
:rtype: bool
"""
ak
=
float
(
"-inf"
)
stk
=
[]
for
i
in
reversed
(
xrange
(
len
(
nums
))):
if
nums
[
i
]
<
ak
:
return
True
while
stk
and
stk
[
-
1
]
<
nums
[
i
]:
ak
=
stk
.
pop
()
stk
.
append
(
nums
[
i
])
return
False
# Time: O(n^2)
# Space: O(1)
class
Solution_TLE
(
object
):
def
find132pattern
(
self
,
nums
):
"""
:type nums: List[int]
:rtype: bool
"""
for
k
in
xrange
(
len
(
nums
)):
valid
=
False
for
j
in
xrange
(
k
):
if
nums
[
j
]
<
nums
[
k
]:
valid
=
True
elif
nums
[
j
]
>
nums
[
k
]:
if
valid
:
return
True
return
False
Back
|
FazBrowse Home
|
New Git URL