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

 

posted on 2019-02-24 12:58  Sempron2800+  阅读(111)  评论(0编辑  收藏  举报