Hi, this is Shunchi!

  • Home

  • Tags0

  • Archives267

  • Categories0

  • Curricula

  • DSA

  • LeetCode_Notes

  • Interviews

  • General

  • Resume

36. Valid Sudoku

Posted on 2020-06-28 | Edited on 2021-01-22

LeetCode

2D Array, HashSet link

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Solution {
public boolean isValidSudoku(char[][] board) {
Set<String> check=new HashSet<>();
for(int i=0;i<9;i++){
for(int j=0;j<9;j++){
char ch=board[i][j];
if(ch!='.'){
if(!check.add(ch+"in row"+i)||
!check.add(ch+"in colum"+j)||
!check.add(ch+"in box"+i/3+"-"+j/3)
){
return false;
}
}
}
}
return true;
}
}

<1…132133134…267>
ShunchiZhou

ShunchiZhou

267 posts
RSS
GitHub E-Mail Gitbook Linkedin
© 2024 ShunchiZhou
Powered by Hexo v5.4.0
|
0%