My code doesn't compile when ideone can compile it successfully


  • 0
    W

    Below is my code.

    When I copy and paste this code to ideone.com and run it. It compiles successfully.

    However, here it says "Compile Error" and does not give me any debug message.

    Can anyone help?

    class Solution
    {
    public:
        static constexpr int blockNums[9][9] = {{'0','0','0','1','1','1','2','2','2'},
                                               {'0','0','0','1','1','1','2','2','2'},
                                               {'0','0','0','1','1','1','2','2','2'},
                                               {'3','3','3','4','4','4','5','5','5'},
                                               {'3','3','3','4','4','4','5','5','5'},
                                               {'3','3','3','4','4','4','5','5','5'},
                                               {'6','6','6','7','7','7','8','8','8'},
                                               {'6','6','6','7','7','7','8','8','8'},
                                               {'6','6','6','7','7','7','8','8','8'}};
                                       
        int getBlockNum(int i, int j)
        {
            return blockNums[i][j];
        }
    
        bool isValidSudoku(vector<vector<char>>& board)
        {
            vector<unordered_set<char>> rowSets;
            vector<unordered_set<char>> colSets;
            vector<unordered_set<char>> blockSets;
            
            for (int i = 0; i < 9; i++)
            {
                rowSets.push_back(std::unordered_set<char>());
            }
            for (int i = 0; i < 9; i++)
            {
                colSets.push_back(std::unordered_set<char>());
            }
            for (int i = 0; i < 9; i++)
            {
                blockSets.push_back(std::unordered_set<char>());
            }
            
            for (int i = 0; i < board.size(); i++)
            {
                auto& boardRow = board.at(i);
                for (int j = 0; j < boardRow.size(); j++)
                {
                    char value = boardRow.at(j);
                    if (value == '.')
                        continue;
                        
                    auto& rowSet = rowSets.at(i);
                    auto& colSet = colSets.at(j);
                    auto& blockSet = blockSets.at(getBlockNum(i, j));
                    
                    if (rowSet.count(value) != 0 || 
                        colSet.count(value) != 0 || 
                        blockSet.count(value) != 0)
                    {
                        return false;
                    }
                    
                    rowSet.insert(value);
                    colSet.insert(value);
                    blockSet.insert(value);
                }
            }
            
            return true;
        }
    };

Log in to reply
 

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