20241024 finished.
This commit is contained in:
@@ -3,16 +3,15 @@
|
||||
*/
|
||||
pub struct Solution {}
|
||||
|
||||
|
||||
// submission codes start here
|
||||
|
||||
impl Solution {
|
||||
pub fn exist(board: Vec<Vec<char>>, word: String) -> bool {
|
||||
let word: Vec<char> = word.chars().collect();
|
||||
|
||||
|
||||
let (m, n) = (board.len(), board[0].len());
|
||||
|
||||
let mut visited = vec![vec![false;n];m];
|
||||
let mut visited = vec![vec![false; n]; m];
|
||||
for i in 0..m {
|
||||
for j in 0..n {
|
||||
if board[i][j] == word[0] {
|
||||
@@ -26,7 +25,14 @@ impl Solution {
|
||||
false
|
||||
}
|
||||
|
||||
fn search(board: &Vec<Vec<char>>, word: &Vec<char>, visited: &mut Vec<Vec<bool>>, x: i32, y: i32, pos: usize) -> bool {
|
||||
fn search(
|
||||
board: &Vec<Vec<char>>,
|
||||
word: &Vec<char>,
|
||||
visited: &mut Vec<Vec<bool>>,
|
||||
x: i32,
|
||||
y: i32,
|
||||
pos: usize,
|
||||
) -> bool {
|
||||
if pos == word.len() {
|
||||
return true;
|
||||
}
|
||||
@@ -36,9 +42,9 @@ impl Solution {
|
||||
if x < 0 || x >= m || y < 0 || y >= n {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
let (x_pos, y_pos) = (x as usize, y as usize);
|
||||
|
||||
|
||||
if visited[x_pos][y_pos] {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user