20241024 finished.

This commit is contained in:
2024-10-24 09:08:13 +08:00
parent 3102da99a8
commit bce8de1c85
266 changed files with 2321 additions and 2014 deletions

View File

@@ -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;
}