MCPcopy Create free account
hub / github.com/Ainevsia/Leetcode-Rust / search

Method search

79. Word Search/src/main.rs:24–47  ·  view source on GitHub ↗
(board: & Vec<Vec<char>>, word: &[char], i: usize, j: usize, used: &mut Vec<Vec<bool>>)

Source from the content-addressed store, hash-verified

22 }
23
24 pub fn search(board: & Vec<Vec<char>>, word: &[char], i: usize, j: usize, used: &mut Vec<Vec<bool>>) -> bool {
25 if word.len() == 0 { return true }
26 if i > 0 && !used[i-1][j] && board[i-1][j] == word[0] {
27 used[i-1][j] = true;
28 if Self::search(board, &word[1..], i-1, j, used) { return true }
29 used[i-1][j] = false;
30 }
31 if j > 0 && !used[i][j-1] && board[i][j-1] == word[0] {
32 used[i][j-1] = true;
33 if Self::search(board, &word[1..], i, j-1, used) { return true }
34 used[i][j-1] = false;
35 }
36 if i < board.len() - 1 && !used[i+1][j] && board[i+1][j] == word[0] {
37 used[i+1][j] = true;
38 if Self::search(board, &word[1..], i+1, j, used) { return true }
39 used[i+1][j] = false;
40 }
41 if j < board[0].len() - 1 && !used[i][j+1] && board[i][j+1] == word[0] {
42 used[i][j+1] = true;
43 if Self::search(board, &word[1..], i, j+1, used) { return true }
44 used[i][j+1] = false;
45 }
46 false
47 }
48}
49
50#[cfg(test)]

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected