Why does my code fail for this test case?


  • 0
    R

    My code failed for this test case

    "..5.....6"
    "....14..."
    "........."
    ".....92.."
    "5....2..."
    ".......3."
    "...54...."
    "3.....42."
    "...27.6.."
    

    Does anyone know why? I'm not sure what I did wrong here.
    Thanks

    class Solution {
    public:
    
        bool isValidSudoku(vector<vector<char> > &board) {
            vector<set<int>> seen1(9);
            vector<vector<set<int>>> seen2(3, vector<set<int>>(3));
            for (int i = 0; i < board.size(); ++i) {
                set<int> cur_seen;
                const vector<char>& row = board[i];
                for (int j = 0; j < row.size(); ++j) {
                    char c = row[i];
                    if (c == '.') continue;
                    if (!cur_seen.insert(c).second) return false;
                    if (!seen1[j].insert(c).second) return false;
                    if (!seen2[i/3][j/3].insert(c).second) return false;
                }
            }
            return true;
        }
    };

  • 0
    Y

    Should be char c = row[j];
    You wrote row[i]


Log in to reply
 

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