详见:https://leetcode.com/problems/valid-sudoku/description/

class Solution {
public:
    bool isValidSudoku(vector<vector<char>>& board) {
         for(int i = 0; i < 9; i ++)
        {
            unordered_map<char, bool> m1;   //check i_th row
            unordered_map<char, bool> m2;   //check i_th column
            unordered_map<char, bool> m3;   //check i_th subgrid
            for(int j = 0; j < 9; j ++)
            {
                if(board[i][j] != '.')
                {
                    if(m1[board[i][j]] == true)
                        return false;
                    m1[board[i][j]] = true;
                }
                if(board[j][i] != '.')
                {
                    if(m2[board[j][i]] == true)
                        return false;
                    m2[board[j][i]] = true;
                }
                if(board[i/3*3+j/3][i%3*3+j%3] != '.')
                {
                    if(m3[board[i/3*3+j/3][i%3*3+j%3]] == true)
                        return false;
                    m3[board[i/3*3+j/3][i%3*3+j%3]] = true;
                }
            }
        }
        return true;
    }
};

 参考:http://www.cnblogs.com/ganganloveu/p/4170632.html

相关文章:

  • 2021-11-29
  • 2021-11-29
  • 2021-11-29
  • 2022-01-19
  • 2021-11-29
  • 2021-11-29
  • 2022-12-23
  • 2021-11-29
猜你喜欢
  • 2021-11-29
  • 2021-07-10
  • 2021-11-29
  • 2021-07-17
  • 2022-01-13
  • 2021-11-29
  • 2021-11-29
相关资源
相似解决方案