@@ -0,0 +1,1663 @@
+/***%0A * Given a 2D board and a word, find if the word exists in the grid.%0A *%0A * The word can be constructed from letters of sequentially adjacent cell, where %22adjacent%22 cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once.%0A *%0A * For example,%0A * Given board =%0A *%0A * %5B%0A *   %5B%22ABCE%22%5D,%0A *   %5B%22SFCS%22%5D,%0A *   %5B%22ADEE%22%5D%0A * %5D%0A * word = %22ABCCED%22, -%3E returns true,%0A * word = %22SEE%22, -%3E returns true,%0A * word = %22ABCB%22, -%3E returns false.%0A */%0Apublic class Solution %7B%0A    // Solution O(n%5E2 * m%5E2) S: O(n%5E2%0A    public boolean exist(char%5B%5D%5B%5D board, String word) %7B%0A        int m = board.length;%0A        int n = board%5B0%5D.length;%0A        boolean visited%5B%5D%5B%5D = new boolean%5Bm%5D%5Bn%5D;%0A        for (int i = 0; i %3C m; i++)%0A            for (int j = 0; j %3C n; j++) %7B%0A                if (dfs(board, visited, i, j, word, 0))%0A                    return true;%0A            %7D%0A        return false;%0A    %7D%0A%0A    private boolean dfs(char %5B%5D%5B%5D board, boolean%5B%5D%5B%5D visited, int i, int j, String word, int index) %7B%0A        if (index == word.length())%0A            return true;%0A        if(i %3C 0 %7C%7C i %3E= board.length %7C%7C j %3C 0 %7C%7C j %3E= board%5B0%5D.length)%0A            return false;%0A        if (visited%5Bi%5D%5Bj%5D) return false;%0A        if (board%5Bi%5D%5Bj%5D != word.charAt(index))  return false;%0A%0A        visited%5Bi%5D%5Bj%5D = true;%0A        boolean ret = dfs(board, visited, i - 1, j, word, index + 1) %7C%7C // up%0A            dfs(board, visited, i + 1, j, word, index + 1) %7C%7C // down%0A            dfs(board, visited, i, j - 1, word, index + 1) %7C%7C // left%0A            dfs(board, visited, i, j + 1, word, index + 1); // right%0A        visited%5Bi%5D%5Bj%5D = false;%0A        return ret;%0A    %7D%0A%7D%0A

add WordSearch.java