-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumRookCaptures.py
More file actions
78 lines (70 loc) · 2.04 KB
/
Copy pathnumRookCaptures.py
File metadata and controls
78 lines (70 loc) · 2.04 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
class Solution:
def searchUp(self):
y = self.y - 1
while y >= 0:
if self.dash[self.x][y] == '.':
y -= 1
continue
elif self.dash[self.x][y] == 'B':
return False
elif self.dash[self.x][y] == 'p':
return True
return False
def searchDown(self):
y = self.y + 1
while y < self.row:
if self.dash[self.x][y] == '.':
y += 1
continue
elif self.dash[self.x][y] == 'B':
return False
elif self.dash[self.x][y] == 'p':
return True
return False
def searchLeft(self):
x = self.x - 1
while x >= 0:
if self.dash[x][self.y] == '.':
x -= 1
continue
elif self.dash[x][self.y] == 'B':
return False
elif self.dash[x][self.y] == 'p':
return True
return False
def searchRight(self):
x = self.x + 1
while x < self.collum:
if self.dash[x][self.y] == '.':
x += 1
continue
elif self.dash[x][self.y] == 'B':
return False
elif self.dash[x][self.y] == 'p':
return True
return False
def __init__(self):
self.row = 0
self.collum = 0
self.dash = []
self.x = 0
self.y = 0
def numRookCaptures(self, board: List[List[str]]) -> int:
self.dash = board
self.row = len(board)
self.collum = len(board[0])
for x in range(0, self.row):
for y in range(0, self.collum):
if board[x][y] == 'R':
self.x = x
self.y = y
count = 0
if self.searchUp():
count += 1
if self.searchDown():
count += 1
if self.searchLeft():
count += 1
if self.searchRight():
count += 1
return count