We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
经典DFS题。
The text was updated successfully, but these errors were encountered:
我的代码:
class Solution { private int w; private int h; public boolean exist(char[][] board, String word) { if (board.length == 0) return false; h = board.length; w = board[0].length; for (int i = 0; i < w; i++) for (int j = 0; j < h; j++) if (search(board, word, 0, i, j)) return true; return false; } public boolean search(char[][] board, String word, int pos, int x, int y){ if (x<0 || x==w || y<0 || y==h || word.charAt(pos) != board[y][x]) return false; if (pos == word.length() -1) return true; char cur = board[y][x]; board[y][x] = 0; boolean find_every_dir = search(board, word, pos+1, x+1, y) || search(board, word, pos+1, x-1, y) || search(board, word, pos+1, x, y+1) || search(board, word, pos+1, x, y-1); board[y][x] = cur; return find_every_dir; } }
Sorry, something went wrong.
No branches or pull requests
经典DFS题。
The text was updated successfully, but these errors were encountered: