8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 59269c3 commit ee2d1deCopy full SHA for ee2d1de
Valid_Sudoku.py
@@ -0,0 +1,22 @@
1
+class Solution:
2
+ # @param board, a 9x9 2D array
3
+ # @return a boolean
4
+ def isValidSudoku(self, board):
5
+ # check rows
6
+ for i in xrange(9):
7
+ if board[i].count('.') + len(set(board[i])) - 1 != 9:
8
+ return False
9
+ # check columns
10
11
+ col = [board[j][i] for j in xrange(9)]
12
+ if col.count('.') + len(set(col)) - 1 != 9:
13
14
+ # check 3x3 squares
15
+ for i in (0, 3, 6):
16
+ for j in (0, 3, 6):
17
+ square = [board[i + m][j + n]
18
+ for m in (0, 1, 2)
19
+ for n in (0, 1, 2)]
20
+ if square.count('.') + len(set(square)) - 1 != 9:
21
22
+ return True
0 commit comments