2025-08-01 17:49:53 +0000 UTC
Available Captures for Rook
Categories:
Links
Code
class Solution:
def numRookCaptures(self, board: List[List[str]]) -> int:
bishop_row, bishop_col = -1, -1
length = len(board)
delta = (
(0, 1), (0, -1), (1, 0), (-1, 0)
)
for row in range(length):
for col in range(length):
if board[row][col] == "R":
bishop_row, bishop_col = row, col
break
if bishop_row != -1:
break
count = 0
for delta_row, delta_col in delta:
row, col = bishop_row, bishop_col
while 0 <= row < length and 0 <= col < length:
char = board[row][col]
if char == "p":
count += 1
break
elif char == "B":
break
row, col = row + delta_row, col + delta_col
return count