leetcode999
Posted AsenYang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode999相关的知识,希望对你有一定的参考价值。
1 class Solution: 2 def numRookCaptures(self, board: ‘List[List[str]]‘) -> int: 3 basei = 0 4 basej = 0 5 row = len(board) 6 coloum = len(board[0]) 7 8 for i in range(row): 9 for j in range(coloum): 10 if board[i][j] == ‘R‘: 11 basei=i 12 basej=j 13 break 14 count = 0 15 for up in range(basei-1,-1,-1): 16 if board[up][basej]==‘B‘: 17 break 18 if board[up][basej]==‘p‘: 19 count+=1 20 break 21 for down in range(basei+1,row): 22 if board[down][basej]==‘B‘: 23 break 24 if board[down][basej]==‘p‘: 25 count+=1 26 break 27 for left in range(basej-1,-1,-1): 28 if board[basei][left]==‘B‘: 29 break 30 if board[basei][left]==‘p‘: 31 count+=1 32 break 33 for right in range(basej+1,coloum): 34 if board[basei][right]==‘B‘: 35 break 36 if board[basei][right]==‘p‘: 37 count+=1 38 break 39 return count
以上是关于leetcode999的主要内容,如果未能解决你的问题,请参考以下文章
leetcode999. Available Captures for Rook
LeetCode --- 999. Available Captures for Rook 解题报告
LeetCode --- 999. Available Captures for Rook 解题报告