-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path36-ValidSudoku.cs
53 lines (38 loc) · 1.56 KB
/
36-ValidSudoku.cs
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class Solution:
def isValidSudoku(self, board: List[List[str]]) -> bool:
rowSets = []
colSets = []
sqaSets = []
for i in range(9): rowSets.append(set())
for i in range(9): colSets.append(set())
for i in range(9): sqaSets.append(set())
rowIndex = 0
colIndex = 0
sqaAbsIndex = 0
sqaIndex = 0
currnetSqaRow = 0
currentCell = board[rowIndex][colIndex]
for idx in range(1, (9 * 9) + 1):
currentSquare = sqaIndex + (3 * currnetSqaRow)
if(currentCell in rowSets[rowIndex]):
return False
elif(currentCell != '.'): rowSets[rowIndex].add(currentCell)
if(currentCell in colSets[colIndex]):
return False
elif(currentCell != '.'): colSets[colIndex].add(currentCell)
if(currentCell in sqaSets[currentSquare]):
return False
elif(currentCell != '.'): sqaSets[currentSquare].add(currentCell)
print((rowIndex, colIndex, currentSquare, sqaIndex, currnetSqaRow))
if((colIndex + 1) % 9 == 0): colIndex = 0
else: colIndex += 1
if((idx + 1) % 9 == 0):
rowIndex += 1
if(idx % 9 == 0):
sqaAbsIndex += 1
if(colIndex % 3 == 0):
sqaIndex += 1
if(sqaIndex % 3 == 0): sqaIndex = 0
if((idx + 1) % 27 == 0): currnetSqaRow += 1
currentCell = board[rowIndex][colIndex]
return True