[leetcode] 36. valid sudoku

Leetcode link for this question

Discription:

Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.

The Sudoku board could be partially filled, where empty cells are filled with the character ‘.’.

A partially filled sudoku which is valid.

Note:

A valid Sudoku board (partially filled) is not necessarily solvable. Only the filled cells need to be validated.

Analyze:

Code 1:

class Solution(object):
    def isValidSudoku(self, board):
        """
        :type board: List[List[str]]
        :rtype: bool
        """
        return 1 == max(collections.Counter(
            x
            for i, row in enumerate(board)  
            for j, c in enumerate(row)
            if c != '.'
            for x in ((c, i), (j, c), (i/3, j/3, c))
        ).values() + [1])

Submission Result:

Status: Accepted
Runtime: 133 ms
Ranking: beats 12.95%