FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-Solutions/Python/grid-illumination.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
/
grid-illumination.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
48 lines (42 loc) · 1.33 KB
Breadcrumbs
LeetCode-Solutions
/
Python
/
grid-illumination.py
Copy path
File metadata and controls
48 lines (42 loc) · 1.33 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
# Time: O(l + q)
# Space: O(l)
import
collections
class
Solution
(
object
):
def
gridIllumination
(
self
,
N
,
lamps
,
queries
):
"""
:type N: int
:type lamps: List[List[int]]
:type queries: List[List[int]]
:rtype: List[int]
"""
directions
=
[(
0
,
-
1
), (
0
,
1
), (
-
1
,
0
), (
1
,
0
),
(
-
1
,
-
1
), (
1
,
-
1
), (
1
,
-
1
), (
1
,
1
)]
lookup
=
set
()
row
=
collections
.
defaultdict
(
int
)
col
=
collections
.
defaultdict
(
int
)
diag
=
collections
.
defaultdict
(
int
)
anti
=
collections
.
defaultdict
(
int
)
for
r
,
c
in
lamps
:
lookup
.
add
((
r
,
c
))
row
[
r
]
+=
1
col
[
c
]
+=
1
diag
[
r
-
c
]
+=
1
anti
[
r
+
c
]
+=
1
result
=
[]
for
r
,
c
in
queries
:
if
row
[
r
]
or
col
[
c
]
or
\
diag
[
r
-
c
]
or
anti
[
r
+
c
]:
result
.
append
(
1
)
else
:
result
.
append
(
0
)
for
d
in
directions
:
nc
,
nr
=
r
+
d
[
0
],
c
+
d
[
1
]
if
not
(
0
<=
nr
<
N
and
0
<=
nc
<
N
and
\
(
nr
,
nc
)
in
lookup
):
continue
lookup
.
remove
((
nr
,
nc
))
row
[
nr
]
-=
1
col
[
nc
]
-=
1
diag
[
nr
-
nc
]
-=
1
anti
[
nr
+
nc
]
-=
1
return
result
Back
|
FazBrowse Home
|
New Git URL