代码拉取完成,页面将自动刷新
class Solution
{
public:
vector<vector<char> > brd;
vector<vector<bool> > flag;
string wrd;
bool isExist(int row, int line, int index)
{
if(index == wrd.size())
return true;
else
{
if(row>=brd.size() || row<0 || line>= brd[0].size() || line<0)
return false;
if(flag[row][line] == true)
return false;
if(wrd[index] == brd[row][line])
{
flag[row][line] = true;
bool temp = ( isExist(row+1,line,index+1)
|| isExist(row,line+1,index+1)
|| isExist(row-1,line,index+1)
|| isExist(row,line-1,index+1));
flag[row][line] = false;
return temp;
}
}
return false;
}
bool exist(vector<vector<char> > &board, string word)
{
brd = board;
wrd = word;
flag.resize(board.size(),vector<bool>(board[0].size(),false));
for(int i=0;i<board.size();i++)
for(int j=0;j<board[i].size();j++)
{
if(isExist(i,j,0))
return true;
}
return false;
}
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。