Created
May 6, 2020 02:01
-
-
Save junminstorage/4c9db7416f33e112ee039fbb42bf1b7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void bfs(char[][] board, int row, int col) { | |
Deque<int[]> q = new ArrayDeque<>(); | |
q.offer(new int[] { row, col }); | |
board[row][col] = '*'; | |
while (!q.isEmpty()) { | |
int[] cell = q.poll(); | |
int r = cell[0], c = cell[1]; | |
for (int[] dir : dirs) { | |
if (r + dir[0] >= 0 && r + dir[0] < rows && c + dir[1] >= 0 && c + dir[1] < cols | |
&& board[r + dir[0]][c + dir[1]] == 'O') { | |
q.offer(new int[] { r + dir[0], c + dir[1] }); | |
board[r + dir[0]][c + dir[1]] = '*'; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment