#include #include #include #include /** * https://leetcode-cn.com/problems/valid-sudoku/description/ * 有效的数独 */ int isValidSudoku(char **board, int boardRowSize, int boardColSize) { for (int i = 0; i < 9; i++) { int hash[9] = {0}; for (int n = 0; n < 9; n++) { if (board[i][n] != '.') { hash[board[i][n] - 49]++; if (hash[board[i][n] - 49] > 1) { return 0; } } } } for (int i = 0; i < 9; i++) { int hash[9] = {0}; for (int n = 0; n < 9; n++) { if (board[n][i] != '.') { hash[board[n][i] - 49]++; if (hash[board[n][i] - 49] > 1) { return 0; } } } } //对小块进行校验 for (int p1 = 0; p1 < 3; p1++) { for (int p = 0; p < 3; p++) { int hash[9] = {0}; for (int i = 0; i < 3; i++) { for (int n = 0; n < 3; n++) { int x = p1 * 3 + i, y = p * 3 + n; if (board[x][y] != '.') { hash[board[x][y] - 49]++; if (hash[board[x][y] - 49] > 1) { return 0; } } } } } } return 1; } /* bool isValidSudoku(char** board, int boardRowSize, int boardColSize) { int i, j, tmp, l; int flag[27][9]; for (i=0; i<27; i++) { for (j=0; j<9; j++) { flag[i][j] = 0; } } for (i=0; i