码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode999

时间:2019-02-24 13:37:48      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:break   return   code   range   span   col   leetcode   count   i+1   

 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

标签:break   return   code   range   span   col   leetcode   count   i+1   

原文地址:https://www.cnblogs.com/asenyang/p/10425878.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!