boolean exist(char[][] a, String word) {
        int r = 1;
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < a[i].length; j++) {
                if (a[i][j] == word.charAt(0)) {
                    char temp = a[i][j];
                    a[i][j] = '.';
                    r = ex(a, word, 1, i, j);
                    a[i][j] = temp;
                }
                if (r == 0) break;
            }
            if (r == 0) break;
        }
        return r == 0;
    }
This is recursive solution without using global variable
src/problems/medium/WordSearch.java