forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0999.py
More file actions
22 lines (21 loc) · 654 Bytes
/
0999.py
File metadata and controls
22 lines (21 loc) · 654 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Solution:
def numRookCaptures(self, board: List[List[str]]) -> int:
R = None
for i in range(8):
for j in range(8):
if board[i][j] == 'R':
R = (i, j)
break
res = 0
for x, y in [[0,1], [0,-1], [1,0], [-1,0]]:
nx = x + R[0]
ny = y + R[1]
while 0 <= nx < 8 and 0 <= ny < 8:
if board[nx][ny] == 'p':
res += 1
break
if board[nx][ny] == 'B':
break
nx += x
ny += y
return res