leetcode-36-有效的數獨
阿新 • • 發佈:2018-11-08
bool isValidSudoku(vector<vector<char>>& board) { int row[9][9] = {0}, col[9][9] = {0}, box[9][9] = {0}; for (int i = 0; i != board.size(); ++i) { for (int j = 0; j != board[i].size(); ++j) { if (board[i][j] != '.') { int num = board[i][j] - '0' - 1; int k = i / 3 * 3 + j / 3; if (row[i][num] || col[j][num] || box[k][num]) return false; row[i][num] = col[j][num] = box[k][num] = 1; } } } return true; }