diff options
author | jack <[email protected]> | 2024-06-14 13:13:15 -0600 |
---|---|---|
committer | jack <[email protected]> | 2024-06-14 13:13:15 -0600 |
commit | d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa (patch) | |
tree | 96df922dae2a5073d9a50ea70c7aae6aa37e3ebe /valid_sudoku.rs | |
download | leetcode-d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa.tar.gz leetcode-d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa.zip |
initial
Diffstat (limited to 'valid_sudoku.rs')
-rw-r--r-- | valid_sudoku.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/valid_sudoku.rs b/valid_sudoku.rs new file mode 100644 index 0000000..3c2f591 --- /dev/null +++ b/valid_sudoku.rs @@ -0,0 +1,27 @@ +struct Solution; + +impl Solution { + pub fn is_valid_sudoku(board: Vec<Vec<char>>) -> bool { + let mut rows: [u16; 9] = [0; 9]; + let mut cols: [u16; 9] = [0; 9]; + let mut blck: [u16; 9] = [0; 9]; + for i in 0..9 { + for j in 0..9 { + match board[i][j] { + '.' => continue, + c => { + let b: usize = (i / 3) * 3 + (j / 3); + let curr = 1 << (c.to_digit(10).unwrap()); + if rows[i] & curr != 0 || cols[j] & curr != 0 || blck[b] & curr != 0 { + return false; + } + rows[i] |= curr; + cols[j] |= curr; + blck[b] |= curr; + } + } + } + } + true + } +} |