class Solution { public: bool isValidSudoku(vector<vector<char>>& board) { for(int i=0;i<9;i++){ unordered_map<char,int> umRow; unordered_map<char,int> umCol; unordered_map<char,int> umSqu; for(int j=0;j<9;j++){ if(board[i][j]!='.'){ if(umRow.find(board[i][j])!=umRow.end()){ return false; } else{ umRow[board[i][j]]=1; } } if(board[j][i]!='.'){ if(umCol.find(board[j][i])!=umCol.end()){ return false; } else{ umCol[board[j][i]]=1; } } int rowIndex=i/3*3+j/3; int colIndex=i%3*3+j%3; if(board[rowIndex][colIndex]!='.'){ if(umSqu.find(board[rowIndex][colIndex])!=umSqu.end()){ return false; } else{ umSqu[board[rowIndex][colIndex]]=1; } } } } return true; } };
参考:
https://blog.csdn.net/mine_song/article/details/70207326