-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprob_36.py
27 lines (25 loc) · 853 Bytes
/
prob_36.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 36. Valid Sudoku
# https://leetcode.com/problems/valid-sudoku/
class Solution(object):
def isValidSudoku(self, board):
"""
:type board: List[List[str]]
:rtype: bool
"""
cols = [{} for i in range(9)]
rows = [{} for i in range(9)]
boxs = [{} for i in range(9)]
for i, row in enumerate(board):
for j, v in enumerate(row):
if v != '.':
if v in cols[j]:
return False
cols[j][v] = 1
if v in rows[i]:
return False
rows[i][v] = 1
box_index = (i // 3 ) * 3 + j // 3
if v in boxs[box_index]:
return False
boxs[box_index][v] = 1
return True