class Solution: # @param board, a 9x9 2D array # @return a boolean def isValidSudoku(self, board): for i in range(9): dup=[] for j in range(9): if board[i][j]!='.': if board[i][j] in dup: return False else: dup.append(board[i][j]) for j in range(9): dup=[] for i in range(9): if board[i][j]!='.': if board[i][j] in dup: return False else: dup.append(board[i][j]) for i in [0,3,6]: for j in [0,3,6]: dup=[] for m in range(3): for n in range(3): if board[i+n][j+m]!='.': if board[i+n][j+m] in dup: return False else: dup.append(board[i+n][j+m]) return True
Tuesday, September 9, 2014
Leetcode: Valid Sudoku @Python
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment