Skip to content

Commit 4dc4303

Browse files
authored
Merge pull request neetcode-gh#2474 from Adimac93/main
fix and simplify rust solution for `0036-valid-sudoku`
2 parents 532626e + 05f0603 commit 4dc4303

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

rust/0036-valid-sudoku.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,22 @@ impl Solution {
1212
for j in 0..9{
1313
let r = board[i][j];
1414
let c = board[j][i];
15-
let b = board[i / 3 * 3 + j / 3][i/3 * 3 + j%3];
15+
let b = board[i / 3 * 3 + j / 3][i % 3 * 3 + j % 3];
1616

1717
if r != '.'{
18-
if !row.contains(&r){
19-
row.insert(r);
20-
}else{
18+
if !row.insert(r){
2119
return false;
2220
}
2321
}
2422

2523
if c != '.'{
26-
if !col.contains(&c){
27-
col.insert(c);
28-
}else{
24+
if !col.insert(c){
2925
return false;
3026
}
3127
}
3228

3329
if b != '.'{
34-
if !bx.contains(&b){
35-
bx.insert(b);
36-
}else{
30+
if !bx.insert(b){
3731
return false;
3832
}
3933
}

0 commit comments

Comments
 (0)