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

Method valid

52. N-Queens II/src/main.rs:30–50  ·  view source on GitHub ↗
(board: &Vec<Vec<char>>, i: usize, j: usize)

Source from the content-addressed store, hash-verified

28 }
29
30 pub fn valid(board: &Vec<Vec<char>>, i: usize, j: usize) -> bool {
31 // check column up
32 for idx in 0..i {
33 if board[idx][j] == 'Q' { return false }
34 }
35 // check diagonal \ up
36 let (mut idx, mut jdx) = (i as i32 - 1, j as i32 - 1);
37 while idx >= 0 && jdx >= 0 {
38 if board[idx as usize][jdx as usize] == 'Q' { return false }
39 idx -= 1;
40 jdx -= 1;
41 }
42 // check diagonal / up
43 let (mut idx, mut jdx) = (i as i32 - 1, j + 1);
44 while idx >= 0 && jdx < board.len() {
45 if board[idx as usize][jdx] == 'Q' { return false }
46 idx -= 1;
47 jdx += 1;
48 }
49 true
50 }
51}
52
53#[cfg(test)]

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected