-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvalid-sudoku.rs
41 lines (34 loc) · 1012 Bytes
/
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
#![allow(dead_code, unused, unused_variables)]
fn main() {}
struct Solution;
impl Solution {
pub fn is_valid_sudoku(board: Vec<Vec<char>>) -> bool {
let mut row = [[0; 10]; 9];
let mut column = [[0; 10]; 9];
let mut boxes = [[[0; 10]; 3]; 3];
for i in 0..9 {
for j in 0..9 {
if board[i][j] == '.' {
continue;
}
let x: usize = board[i][j].to_string().parse().unwrap();
if row[i][x] != 0 {
return false;
} else {
row[i][x] = 1;
}
if column[j][x] != 0 {
return false;
} else {
column[j][x] = 1;
}
if boxes[i / 3][j / 3][x] != 0 {
return false;
} else {
boxes[i / 3][j / 3][x] = 1;
}
}
}
true
}
}