forked from neetcode-gh/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0036-valid-sudoku.rs
43 lines (34 loc) · 1.08 KB
/
0036-valid-sudoku.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use std::collections::HashSet;
impl Solution {
pub fn is_valid_sudoku(board: Vec<Vec<char>>) -> bool {
let mut row: HashSet<char> = HashSet::new();
let mut col: HashSet<char> = HashSet::new();
let mut bx : HashSet<char> = HashSet::new();
for i in 0..9{
for j in 0..9{
let r = board[i][j];
let c = board[j][i];
let b = board[i / 3 * 3 + j / 3][i % 3 * 3 + j % 3];
if r != '.'{
if !row.insert(r){
return false;
}
}
if c != '.'{
if !col.insert(c){
return false;
}
}
if b != '.'{
if !bx.insert(b){
return false;
}
}
}
row.clear();
col.clear();
bx.clear();
}
true
}
}