FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-Solutions/Python/available-captures-for-rook.py at master · junlelu/LeetCode-Solutions · GitHub
junlelu
LeetCode-Solutions
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
LeetCode-Solutions
/
Python
/
available-captures-for-rook.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
30 lines (27 loc) · 799 Bytes
Breadcrumbs
LeetCode-Solutions
/
Python
/
available-captures-for-rook.py
Copy path
File metadata and controls
30 lines (27 loc) · 799 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
# Time: O(1)
# Space: O(1)
class
Solution
(
object
):
def
numRookCaptures
(
self
,
board
):
"""
:type board: List[List[str]]
:rtype: int
"""
directions
=
[(
0
,
1
), (
1
,
0
), (
0
,
-
1
), (
-
1
,
0
)]
r
,
c
=
None
,
None
for
i
in
xrange
(
8
):
if
r
is
not
None
:
break
for
j
in
xrange
(
8
):
if
board
[
i
][
j
]
==
'R'
:
r
,
c
=
i
,
j
break
result
=
0
for
d
in
directions
:
nr
,
nc
=
r
+
d
[
0
],
c
+
d
[
1
]
while
0
<=
nr
<
8
and
0
<=
nc
<
8
:
if
board
[
nr
][
nc
]
==
'p'
:
result
+=
1
if
board
[
nr
][
nc
]
!=
'.'
:
break
nr
,
nc
=
nr
+
d
[
0
],
nc
+
d
[
1
]
return
result
Back
|
FazBrowse Home
|
New Git URL