999. Available Captures for Rook Easy

@problem@discussion
#Array#Matrix#Simulation



1/**
2 * [999] Available Captures for Rook
3 *
4 * On an 8 x 8 chessboard, there is exactly one white rook 'R' and some number of white bishops 'B', black pawns 'p', and empty squares '.'.
5 * When the rook moves, it chooses one of four cardinal directions (north, east, south, or west), then moves in that direction until it chooses to stop, reaches the edge of the board, captures a black pawn, or is blocked by a white bishop. A rook is considered attacking a pawn if the rook can capture the pawn on the rook's turn. The number of available captures for the white rook is the number of pawns that the rook is attacking.
6 * Return the number of available captures for the white rook.
7 *  
8 * Example 1:
9 * <img alt="" src="https://assets.leetcode.com/uploads/2019/02/20/1253_example_1_improved.PNG" style="width: 300px; height: 305px;" />
10 * Input: board = [[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".","R",".",".",".","p"],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."]]
11 * Output: 3
12 * Explanation: In this example, the rook is attacking all the pawns.
13 * 
14 * Example 2:
15 * <img alt="" src="https://assets.leetcode.com/uploads/2019/02/19/1253_example_2_improved.PNG" style="width: 300px; height: 306px;" />
16 * Input: board = [[".",".",".",".",".",".",".","."],[".","p","p","p","p","p",".","."],[".","p","p","B","p","p",".","."],[".","p","B","R","B","p",".","."],[".","p","p","B","p","p",".","."],[".","p","p","p","p","p",".","."],[".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".","."]]
17 * Output: 0
18 * Explanation: The bishops are blocking the rook from attacking any of the pawns.
19 * 
20 * Example 3:
21 * <img alt="" src="https://assets.leetcode.com/uploads/2019/02/20/1253_example_3_improved.PNG" style="width: 300px; height: 305px;" />
22 * Input: board = [[".",".",".",".",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".","p",".",".",".","."],["p","p",".","R",".","p","B","."],[".",".",".",".",".",".",".","."],[".",".",".","B",".",".",".","."],[".",".",".","p",".",".",".","."],[".",".",".",".",".",".",".","."]]
23 * Output: 3
24 * Explanation: The rook is attacking the pawns at positions b5, d6, and f5.
25 * 
26 *  
27 * Constraints:
28 * 
29 * 	board.length == 8
30 * 	board[i].length == 8
31 * 	board[i][j] is either 'R', '.', 'B', or 'p'
32 * 	There is exactly one cell with board[i][j] == 'R'
33 * 
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/available-captures-for-rook/
38// discuss: https://leetcode.com/problems/available-captures-for-rook/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43    pub fn num_rook_captures(board: Vec<Vec<char>>) -> i32 {
44        0
45    }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_999() {
56    }
57}
58


Back
© 2025 bowen.ge All Rights Reserved.