FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-Solutions/Python/walls-and-gates.py at master · tehsints/LeetCode-Solutions · GitHub
tehsints
LeetCode-Solutions
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
LeetCode-Solutions
/
Python
/
walls-and-gates.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
22 lines (18 loc) · 695 Bytes
Breadcrumbs
LeetCode-Solutions
/
Python
/
walls-and-gates.py
Copy path
File metadata and controls
22 lines (18 loc) · 695 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
# Time: O(m * n)
# Space: O(g)
from
collections
import
deque
class
Solution
(
object
):
def
wallsAndGates
(
self
,
rooms
):
"""
:type rooms: List[List[int]]
:rtype: void Do not return anything, modify rooms in-place instead.
"""
INF
=
2147483647
q
=
deque
([(
i
,
j
)
for
i
,
row
in
enumerate
(
rooms
)
for
j
,
r
in
enumerate
(
row
)
if
not
r
])
while
q
:
(
i
,
j
)
=
q
.
popleft
()
for
I
,
J
in
(
i
+
1
,
j
), (
i
-
1
,
j
), (
i
,
j
+
1
), (
i
,
j
-
1
):
if
0
<=
I
<
len
(
rooms
)
and
0
<=
J
<
len
(
rooms
[
0
])
and
\
rooms
[
I
][
J
]
==
INF
:
rooms
[
I
][
J
]
=
rooms
[
i
][
j
]
+
1
q
.
append
((
I
,
J
))
Back
|
FazBrowse Home
|
New Git URL