forked from neetcode-gh/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0036-valid-sudoku.go
34 lines (25 loc) · 1.04 KB
/
0036-valid-sudoku.go
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
// Time Complexity O(n2)
func isValidSudoku(board [][]byte) bool {
hashMap := make(map[string]bool)
for i:=0; i<9; i ++ {
for j:=0;j<9; j++ {
row:= i
column :=j
current_val :=string(board[i][j])
if current_val =="." {
continue
}
_,ok1 := hashMap[current_val + "found in row" + string(row)]
_,ok2 := hashMap[current_val + "found in column"+ string(column)]
_,ok3 := hashMap[current_val + "found in grid" + string(i/3) + "-" + string(j/3)]
if ok1 ||ok2||ok3{
return false
} else {
hashMap[current_val + "found in row" + string(row)] = true
hashMap[current_val + "found in column"+ string(column)] = true
hashMap[current_val + "found in grid" + string(i/3) + "-" + string(j/3)]= true
}
}
}
return true
}