1. 程式人生 > >LeetCode Day30 valid-sudoku

LeetCode Day30 valid-sudoku

class Solution {
public:
    bool isValidSudoku(vector<vector<char>>& board) {
        if(board.empty() || board[0].empty()) return false;
        int m=board.size(),n=board[0].size();
        vector<vector<bool>> rowflag(m,vector<bool>(n,false));
        vector<
vector<bool>> colflag(n,vector<bool>(m,false)); vector<vector<bool>> cellflag(m,vector<bool>(n,false)); for(int i=0;i<m;i++) for(int j=0;j<n;j++){ if(board[i][j]>='0' && board[i][j]<='9'){ int
c=board[i][j]-'1'; if(rowflag[i][c]||colflag[j][c]||cellflag[i/3+(j/3)*3][c]) return false; rowflag[i][c]=true;colflag[j][c]=true;cellflag[i/3+(j/3)*3][c]=true; } } return true; } };