OJ Bug?My code in C++ passed but code in C not. Code run correctly in my PC.


  • 1
    S

    I code in both C++ and C. and the code structure is same. However, the code in C++ passed while the code in C can't pass.

    The OJ system said:

    Input: [".87654321","2........","3........","4........","5........","6........","7........","8........","9........"]
    Output: false
    Expected: true

    But the code in C runs correctly in my PC.

    Follows my code in C.

    void reset(bool repeat[]) {
        for (int i = 0; i < 9; ++i)
            repeat[i] = false;
    }
    
    bool isValidSudoku(char board[9][9]) {
        bool repeat[9];
        int i, j, k, l, m;
        for (i = 0; i < 9; ++i) {
            reset(repeat);
            for (j = 0; j < 9; ++j) {
                if (board[i][j] == '.')
                    continue;
                if (repeat[board[i][j] - '0' - 1])
                    return false;
                else
                    repeat[board[i][j] - '0' - 1] = true;
            }
        }
    
        for (j = 0; j < 9; ++j) {
            reset(repeat);
            for (i = 0; i < 9; ++i) {
                if (board[i][j] == '.')
                    continue;
                if (repeat[board[i][j] - '0' - 1])
                    return false;
                else
                    repeat[board[i][j] - '0' - 1] = true;
            }
        }
    
        for (i = 0; i < 9; i += 3) {
            for (j = 0; j < 9; j += 3) {
                reset(repeat);
                for (k = 0; k < 3; ++k) {
                    for (l = 0; l < 3; ++l) {
                        if (board[i + k][j + l] == '.')
                            continue;
                        if (repeat[board[i + k][j + l] - '0' - 1])
                            return false;
                        else
                            repeat[board[i + k][j + l] - '0' - 1] = true;
                    }
                }
            }
        }
    
        return true;
    }

  • -1
    H

    you should change "repeapt[9]" to "repeapt[10]"


Log in to reply
 

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