力扣 79 搜尋單詞

2022-04-09 13:46:45 字數 613 閱讀 1936

題目:傳送門

用深度優先搜尋就行了,注意只能上下左右四個方向,注意不能越出界限,走過的地方不能重複走。**的條件有點多,注意細節。

#include #include 

#include

#include

using

namespace

std;

typedef vector

vec;

typedef vector

mat;

int dx[4] = ;

int dy[4] = ;

class

solution

for(int i = index; i < word.length(); i++)

}return

false

; }

return

false;//

若未返回true,主函式呼叫處返回false

}

bool exist(vectorchar>>& board, string

word)

return

false

; }

};

力扣79 單詞搜尋

給定乙個二維網格和乙個單詞,找出該單詞是否存在於網格中。單詞必須按照字母順序,通過相鄰的單元格內的字母構成,其中 相鄰 單元格是那些水平相鄰或垂直相鄰的單元格。同乙個單元格內的字母不允許被重複使用。示例 board a b c e s f c s a d e e 給定 word abcced 返回 ...

力扣79 單詞搜尋

class solution return false public boolean existhelper char board,boolean used,char word,int idx,int col,int row if used row col true board row col wo...

力扣 79 單詞搜尋

題目 直接看劍指offer第六十五題矩陣中的路徑 給定乙個二維網格和乙個單詞,找出該單詞是否存在於網格中。單詞必須按照字母順序,通過相鄰的單元格內的字母構成,其中 相鄰 單元格是那些水平相鄰或垂直相鄰的單元格。同乙個單元格內的字母不允許被重複使用。示例 board a b c e s f c s a...