Skip to content

Instantly share code, notes, and snippets.

@junminstorage
Created May 6, 2020 02:01
Show Gist options
  • Save junminstorage/4c9db7416f33e112ee039fbb42bf1b7b to your computer and use it in GitHub Desktop.
Save junminstorage/4c9db7416f33e112ee039fbb42bf1b7b to your computer and use it in GitHub Desktop.
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