Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 21 additions & 30 deletions go/0036-valid-sudoku.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,25 @@
// 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])
rows := [9][9]bool{}
cols := [9][9]bool{}
squares := [9][9]bool{}

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
}
}
for r := range 9 {
for c := range 9 {
if board[r][c] == '.' {
continue
}

}
return true

value := board[r][c] - '1'
s := r/3*3 + c/3
if rows[r][value] || cols[c][value] || squares[s][value] {
return false
}

rows[r][value] = true
cols[c][value] = true
squares[s][value] = true
}
}

return true
}