File tree Expand file tree Collapse file tree 2 files changed +16
-13
lines changed
src/leetcode/medium/valid-sedoku Expand file tree Collapse file tree 2 files changed +16
-13
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,9 @@ init-hook="import sys; sys.path.append('./')"
3
3
ignore =tests
4
4
5
5
[MESSAGES CONTROL]
6
- disable =C0111, # missing-docstring
6
+ disable =C0103, # invalid-name
7
+ C0111, # missing-docstring
8
+ C0200, # consider-using-enumerate
7
9
C0301, # line-too-long
8
10
R0903, # too-few-public-methods
9
11
Original file line number Diff line number Diff line change 44
44
45
45
from typing import List
46
46
47
+
47
48
def isValidSudoku (board : List [List [str ]]) -> bool :
48
49
prevSeen = {
49
- "rows" : { num : {} for num in range (len (board )) },
50
- "columns" : { num : {} for num in range (len (board [0 ])) }
50
+ "rows" : {num : {} for num in range (len (board ))},
51
+ "columns" : {num : {} for num in range (len (board [0 ]))}
51
52
}
52
53
buckets = [[{} for _ in range (3 )] for _ in range (3 )]
53
-
54
+
54
55
for y in range (len (board )):
55
56
for x in range (len (board [y ])):
56
57
currentNum = board [y ][x ]
57
-
58
- if ( currentNum == "." ) :
58
+
59
+ if currentNum == "." :
59
60
continue
60
-
61
+
61
62
if currentNum in prevSeen ["rows" ][y ]:
62
63
return False
63
64
if currentNum in prevSeen ["columns" ][x ]:
64
65
return False
65
-
66
+
66
67
prevSeen ["rows" ][y ][currentNum ] = True
67
68
prevSeen ["columns" ][x ][currentNum ] = True
68
-
69
+
69
70
bucketY = y // 3
70
71
bucketX = x // 3
71
-
72
+
72
73
if currentNum in buckets [bucketY ][bucketX ]:
73
74
return False
74
-
75
+
75
76
buckets [bucketY ][bucketX ][currentNum ] = True
76
-
77
- return True
77
+
78
+ return True
You can’t perform that action at this time.
0 commit comments