-
-
Save jronal/174c1ba9a1deb489df7701a2f2077d56 to your computer and use it in GitHub Desktop.
sudoku codefights
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
| boolean sudoku2(char[][] grid) { | |
| int n = grid.length; | |
| int[] filaVerifica = new int[n]; | |
| int[] columnaVerfica = new int[n]; | |
| int[] escaque = new int[n]; | |
| for (int i = 0; i < n; i++) { | |
| Arrays.fill(filaVerifica, 0); | |
| Arrays.fill(columnaVerfica, 0); | |
| Arrays.fill(escaque, 0); | |
| for (int j = 0; j < n; j++) { | |
| // verificar filas | |
| if (grid[i][j] != '.') { | |
| int index = Character.getNumericValue(grid[i][j]); | |
| filaVerifica[index - 1] += 1; | |
| } | |
| // verificar columnas | |
| if (grid[j][i] != '.') { | |
| int index = Character.getNumericValue(grid[j][i]); | |
| columnaVerfica[index - 1] += 1; | |
| } | |
| // verificar escaques | |
| if (grid[j / 3 + (i / 3) * 3][j % 3 + (i % 3) * 3] != '.') { | |
| int index = Character.getNumericValue(grid[j / 3 + (i / 3) * 3][j % 3 + (i % 3) * 3]); | |
| escaque[index - 1] += 1; | |
| } | |
| } | |
| for (int z = 0; z < n; z++) { | |
| if (filaVerifica[z] > 1) return false; | |
| if (columnaVerfica[z] > 1) return false; | |
| if (escaque[z] > 1) return false; | |
| } | |
| } | |
| return true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment