My AC Java Solution


  • 1
    N
    public boolean isValidSudoku(char[][] board) {
        if (board.length == 0 || board[0].length == 0) return false;
        int[][] map = new int[27][10];
        //0 - 8 rows, 9 - 17 cols, 18 - 26 square
        for (int i = 0; i < board.length; i++) {
            for (int j = 0; j < board[0].length; j++) {
                if (board[i][j] == '.') continue;
                if (map[i][board[i][j] - '1']++ > 0 || map[9 + j][board[i][j] - '1']++ > 0 || map[18 + i / 3 * 3+ j / 3][board[i][j] - '1']++ > 0) return false;
            }
        }
        return true;
    }

Log in to reply
 

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