-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidSudoku.py
More file actions
25 lines (22 loc) · 857 Bytes
/
validSudoku.py
File metadata and controls
25 lines (22 loc) · 857 Bytes
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
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# Source: https://leetcode.com/problems/valid-sudoku/
# Author: Miao Zhang
# Date: 2021-01-08
class Solution:
def isValidSudoku(self, board: List[List[str]]) -> bool:
row = [{}, {}, {}, {}, {},{}, {}, {}, {}]
col = [{}, {}, {}, {}, {},{}, {}, {}, {}]
cell = [{}, {}, {}, {}, {},{}, {}, {}, {}]
for i in range(9):
for j in range(9):
unitnum = 3 * (i // 3) + j // 3
val = board[i][j]
if val != '.':
if val not in row[i] and val not in col[j] and val not in cell[unitnum]:
row[i][val] = 1
col[j][val] = 1
cell[unitnum][val] = 1
else:
return False
return True