-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path999.py
66 lines (55 loc) · 2.15 KB
/
999.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
__________________________________________________________________________________________________
sample 28 ms submission
class Solution:
def numRookCaptures(self, board: List[List[str]]) -> int:
for i in range(8):
for j in range(8):
if board[i][j] == 'R':
x0, y0 = i, j
res = 0
for i, j in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
x, y = x0+i, y0+j
while 0 <= x <8 and 0<= y <8:
if board[x][y] == 'p': res +=1
if board[x][y] != '.': break
x, y = x+i, y+j
return res
__________________________________________________________________________________________________
sample 13052 kb submission
class Solution:
def numRookCaptures(self, board: List[List[str]]) -> int:
result = 0
pos = 0
for r in range(8):
if "R" in board[r]:
q = board[r].index("R")
else:
continue
if q >= 0:
for i in range(q+1,8):
if (board[r][i] != "p" and board[r][i] != "."):
break
if board[r][i] == "p":
result += 1
break
for i in range(q-1, -1, -1):
if (board[r][i] != "p" and board[r][i] != "."):
break
if board[r][i] == "p":
result += 1
break
break
for i in range(r+1,8):
if (board[i][q] != "p" and board[i][q] != "."):
break
if board[i][q] == "p":
result += 1
break
for i in range(r-1, -1, -1):
if (board[i][q] != "p" and board[i][q] != "."):
break
if board[i][q] == "p":
result += 1
break
return result
__________________________________________________________________________________________________