class Solution { public: bool isValidSudoku(vector<vector<char>>& board) { int rows[9][9];//建造一个二维数组,记录行 int columns[9][9];//建造一个二维数组,记录列 int subboxes[3][3][9];//建造一个三维数组;记录全部的数字 memset(rows,0,sizeof(rows)); memset(columns,0,sizeof(columns)); memset(subboxes,0,sizeof(subboxes)); for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { char c = board[i][j]; if (c != '.') { int index = c - '0' - 1; rows[i][index]++; columns[j][index]++; subboxes[i / 3][j / 3][index]++; if (rows[i][index] > 1 || columns[j][index] > 1 || subboxes[i / 3][j / 3][index] > 1) { return false; } } } } return true; } };
标签:index,rows,subboxes,--,++,int,columns,数据结构,数独 From: https://www.cnblogs.com/jerry-autumn/p/16728759.html