classSolution: defnumRookCaptures(self, board: List[List[str]]) -> int: length = 8 x = -1 y = -1 for i in range(length): for j in range(length): if board[i][j] == 'R': x = i y = j break if x != -1: break
count = 0 row = board[x] column = [board[i][y] for i in range(length)] count += self.find(row, y-1, y+1, length) count += self.find(column, x-1, x+1, length) return count
deffind(self, arr, i, j, length): count = 0 while i > -1: if arr[i] == 'p': count += 1 break elif arr[i] == 'B': break i -= 1 while j < length: if arr[j] == 'p': count += 1 break elif arr[j] == 'B': break j += 1 return count