// @lc code=start classSolution { private: int d[4][2] = {{-1,0}, {0,1}, {1,0}, {0,-1}}; int m, n; vector<vector<bool>> visited;
boolsearchWord(constvector<vector<char>>& board, conststring word, int index, int startx, int starty){ if(index==word.size()-1){ return board[startx][starty]==word[index]; }
if(board[startx][starty]==word[index]){ visited[startx][starty]=true; for(int i=0; i<4; ++i){ int newx = startx+d[i][0]; int newy = starty+d[i][1]; if(inArea(newx, newy) && !visited[newx][newy] && searchWord(board, word, index+1, newx, newy)) returntrue; } visited[startx][starty]=false; } returnfalse; }