Share my simple c++ code with using unsorted_set

  • 0
    class Solution {
        bool isValidSudoku(vector<vector<char>>& board) {
    		   unordered_set<char> row[9];
    		   unordered_set<char> col[9];
    		   unordered_set<char> cell[3][3];
    		   for(int i=0; i<9; ++i)
    				for(int j=0; j<9; ++j)
    					char n = board[i][j];
    					int x = i / 3;
    					int y = j / 3;
    					if(isdigit (n) && (!row[i].insert(n).second || !col[j].insert(n).second || !cell[x][y].insert(n).second))
    						return false;
    		   return true;

  • 0

    I think unordered_set shoud not be used in this place,seem strange, you need to redesign you Hash and Compare when element is not the c++ fundamental type。

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.