FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-Solutions/Python/self-crossing.py at master · pythonpeixun/LeetCode-Solutions · GitHub
pythonpeixun
/
LeetCode-Solutions
Public
forked from
kamyu104/LeetCode-Solutions
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
LeetCode-Solutions
/
Python
/
self-crossing.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
37 lines (34 loc) · 1.09 KB
Breadcrumbs
LeetCode-Solutions
/
Python
/
self-crossing.py
Copy path
File metadata and controls
37 lines (34 loc) · 1.09 KB
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
# Time: O(n)
# Space: O(1)
class
Solution
(
object
):
def
isSelfCrossing
(
self
,
x
):
"""
:type x: List[int]
:rtype: bool
"""
if
len
(
x
)
>=
5
and
x
[
3
]
==
x
[
1
]
and
x
[
4
]
+
x
[
0
]
>=
x
[
2
]:
# Crossing in a loop:
# 2
# 3 ┌────┐
# └─══>┘1
# 4 0 (overlapped)
return
True
for
i
in
xrange
(
3
,
len
(
x
)):
if
x
[
i
]
>=
x
[
i
-
2
]
and
x
[
i
-
3
]
>=
x
[
i
-
1
]:
# Case 1:
# i-2
# i-1┌─┐
# └─┼─>i
# i-3
return
True
elif
i
>=
5
and
x
[
i
-
4
]
<=
x
[
i
-
2
]
and
x
[
i
]
+
x
[
i
-
4
]
>=
x
[
i
-
2
]
and
\
x
[
i
-
1
]
<=
x
[
i
-
3
]
and
x
[
i
-
5
]
+
x
[
i
-
1
]
>=
x
[
i
-
3
]:
# Case 2:
# i-4
# ┌──┐
# │i<┼─┐
# i-3│ i-5│i-1
# └────┘
# i-2
return
True
return
False
Back
|
FazBrowse Home
|
New Git URL