Java solution~ Ծ‸ Ծ


  • 0
    X
    public boolean isValidSudoku(char[][] board) {
        boolean[][] row = new boolean[9][9];
        boolean[][] columns = new boolean[9][9];
        boolean[][][] cube = new boolean[3][3][9];
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                if (board[i][j] == '.') continue;
                int k = board[i][j] - '1';
                if (row[i][k] || columns[j][k] || cube[i / 3][j / 3][k]) {
                    return false;
                } else {
                    row[i][k] = true;
                    columns[j][k] = true;
                    cube[i / 3][j / 3][k] = true;
                }
            }
        }
        return true;
    }
    

Log in to reply
 

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