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 =
Given board =
[
["ABCE"],
["SFCS"],
["ADEE"]
]
word = "ABCCED"
, -> returns true
,word =
"SEE"
, -> returns true
,word =
"ABCB"
, -> returns false
.Solution: recursion.
Note that if we change vector<vector<char> > &board to vector<vector<char> > board, the code does not pass the large judge. If the vector is transferred by value, the parameter is created a copy of the vector you send in. Every time the method it called, the temporary variable is created and copied.
Comments
Post a Comment