Leetcode -- Word Search

https://oj.leetcode.com/problems/word-search/

Given a 2D board and a word, find if the word exists in the grid.

The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once.

For example,
Given board =

`[  ["ABCE"],  ["SFCS"],  ["ADEE"]]`
word = `"ABCCED"`, -> returns `true`,
word = `"SEE"`, -> returns `true`,
word = `"ABCB"`, -> returns `false`.

public boolean exist(char[][] board, String word)

`    public boolean exist(char[][] board, String word) {        boolean[][] visited = new boolean[board.length][board[0].length];        for(int i = 0; i < board.length; i++){            for(int j = 0; j < board[0].length; j++){                if(helper(visited, board, i, j, 0, word))                    return true;            }        }        return false;    }        public boolean helper(boolean[][] visited, char[][] board, int x, int y, int cur_len, String word){        if(x < 0 || x >= board.length || y < 0 || y >= board[0].length || visited[x][y])            return false;        if(word.charAt(cur_len) == board[x][y]){            if(cur_len == word.length() - 1)                return true;            visited[x][y] = true;            if(helper(visited, board, x - 1, y, cur_len + 1, word) || helper(visited, board, x + 1, y, cur_len + 1, word) || helper(visited, board, x, y + 1, cur_len + 1, word) || helper(visited, board, x, y - 1, cur_len + 1, word))                return true;            visited[x][y] = false;            return false;        }else            return false;    }`

0 0