knakul853

Untitled

Jun 12th, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. /**
  2. knaul853
  3.  
  4. //https://stackoverflow.com/a/10163885/9959901
  5. **/
  6. class Solution {
  7. public:
  8.     bool isValidSudoku(vector<vector<char>>& board) {
  9.        
  10.         unordered_set<char> row[9],col[9],square[3][3];
  11.        
  12.         for(int i=0;i<9;i++){
  13.             for(int j=0;j<9;j++){
  14.                
  15.                 char ch = board[i][j];
  16.                
  17.                 if(ch !='.'){
  18.                    
  19.                     if(!row[i].insert(ch).second || !col[j].insert(ch).second
  20.                                        || !square[i/3][j/3].insert(ch).second) return false;
  21.                 }
  22.             }
  23.         }
  24.        
  25.         return true;
  26.     }
  27. };
Add Comment
Please, Sign In to add comment