Available Captures for Rook LeetCode solution in Java
1class Solution {2public int numRookCaptures(char[][] board) {3int ans = 0;45int row = 0;6int col = 0;7for (int i = 0; i < 8; i++) {8for (int j = 0; j < 8; j++) {9if (board[i][j] == 'R') {10row = i;11col = j;12break;13}14}15}1617int j = col;18while (j >= 0) {19if (board[row][j] == 'B') {20break;21} else if (board[row][j] == 'p') {22ans++;23break;24}2526j--;27}2829j = col;30while (j <= board[0].length - 1) {31if (board[row][j] == 'B') {32break;33} else if (board[row][j] == 'p') {34ans++;35break;36}3738j++;39}4041int i = row;42while (i <= board.length - 1) {43if (board[i][col] == 'B') {44break;45} else if (board[i][col] == 'p') {46ans++;47break;48}4950i++;51}5253i = row;54while (i >= 0) {55if (board[i][col] == 'B') {56break;57} else if (board[i][col] == 'p') {58ans++;59break;60}6162i--;63}6465return ans;66}67}