Created
April 11, 2020 13:29
-
-
Save Skarlso/23c3e2e653d7ccede6d1b6efdb72a157 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func isValidSudoku(board [][]byte) bool { | |
var colV [9][9]int | |
var rowV [9][9]int | |
var boxV [9][9]int | |
for row := 0; row < 9; row++ { | |
for col := 0; col < 9; col++ { | |
value := board[row][col] - '0' | |
if value > 0 && value <= 9 { | |
if rowV[row][value-1] != 0 || colV[col][value-1] != 0 { | |
return false | |
} | |
key := ((row/3)*3) + (col/3) | |
if boxV[key][value-1] != 0 { | |
return false | |
} | |
rowV[row][value-1] = 1 | |
colV[col][value-1] = 1 | |
boxV[key][value-1] = 1 | |
} | |
} | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment