Please tell me what's wrong with my code?


  • 0
    X

    class Solution {
    public:
    bool isValidSudoku(vector< vector<char> >& board) {
    int size = 9;
    vector<vector<char>> col;
    vector<vector<char>> group;

        for (int i=0; i<size;i++){
            for(int j=0; j<size;j++){
                char temp = board[i][j];
                col[j].push_back(temp);
                group[(i/3*3)+j/3].push_back(temp);
            }
        }
        // judge if Valid
        return judge(board) && judge(col) && judge(group);
    }
    
    bool judge(vector<vector<char>>& nums){
        int size = 9;
        for (int i=0; i<size;i++){
            set<char> s;
            for(int j=0; j<size;j++){
                if(!nums[i][j]=='.') {
                    if(!s.count(nums[i][j])) s.insert(nums[i][j]);
                    else return false;
                } 
            }
        }
        return true;
    }
    

    };


Log in to reply
 

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