FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-Solutions/Python/range-module.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
/
range-module.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
69 lines (59 loc) · 1.77 KB
Breadcrumbs
LeetCode-Solutions
/
Python
/
range-module.py
Copy path
File metadata and controls
69 lines (59 loc) · 1.77 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
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
# Time: addRange: O(n)
# removeRange: O(n)
# queryRange: O(logn)
# Space: O(n)
import
bisect
class
RangeModule
(
object
):
def
__init__
(
self
):
self
.
__intervals
=
[]
def
addRange
(
self
,
left
,
right
):
"""
:type left: int
:type right: int
:rtype: void
"""
tmp
=
[]
i
=
0
for
interval
in
self
.
__intervals
:
if
right
<
interval
[
0
]:
tmp
.
append
((
left
,
right
))
break
elif
interval
[
1
]
<
left
:
tmp
.
append
(
interval
)
else
:
left
=
min
(
left
,
interval
[
0
])
right
=
max
(
right
,
interval
[
1
])
i
+=
1
if
i
==
len
(
self
.
__intervals
):
tmp
.
append
((
left
,
right
))
while
i
<
len
(
self
.
__intervals
):
tmp
.
append
(
self
.
__intervals
[
i
])
i
+=
1
self
.
__intervals
=
tmp
def
queryRange
(
self
,
left
,
right
):
"""
:type left: int
:type right: int
:rtype: bool
"""
i
=
bisect
.
bisect_left
(
self
.
__intervals
, (
left
,
float
(
"inf"
)))
if
i
:
i
-=
1
return
bool
(
self
.
__intervals
)
and
\
self
.
__intervals
[
i
][
0
]
<=
left
and
\
right
<=
self
.
__intervals
[
i
][
1
]
def
removeRange
(
self
,
left
,
right
):
"""
:type left: int
:type right: int
:rtype: void
"""
tmp
=
[]
for
interval
in
self
.
__intervals
:
if
interval
[
1
]
<=
left
or
interval
[
0
]
>=
right
:
tmp
.
append
(
interval
)
else
:
if
interval
[
0
]
<
left
:
tmp
.
append
((
interval
[
0
],
left
))
if
right
<
interval
[
1
]:
tmp
.
append
((
right
,
interval
[
1
]))
self
.
__intervals
=
tmp
Back
|
FazBrowse Home
|
New Git URL