-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path999.cpp
More file actions
25 lines (25 loc) · 692 Bytes
/
Copy path999.cpp
File metadata and controls
25 lines (25 loc) · 692 Bytes
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
class Solution { // 0ms
public:
int numRookCaptures(vector<vector<char>> &b) {
const vector<pair<int, int>> dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int ret = 0;
for (auto i = 0; i < b.size(); ++i)
for (auto j = 0; j < b[i].size(); ++j)
if (b[i][j] == 'R') {
for (const auto [dx, dy] : dir) {
int x = i, y = j;
while (x >= 0 && x < b.size() && y >= 0 && y < b[x].size() &&
b[x][y] != 'B') {
if (b[x][y] == 'p') {
++ret;
break;
}
x += dx;
y += dy;
}
}
break;
}
return ret;
}
};