Submission Detail

507 / 507 test cases passed.
Status:

Accepted

Runtime: 91 ms
Memory Usage: 13.6 MB
Submitted: 0 minutes ago
loading
Runtime Error Message:
Last executed input:
Input:
Output:
Expected:

Accepted Solutions Runtime Distribution

40
50
60
70
80
90
100
110
120
1
2
3
4
5
6
7
python
You are here!
Your runtime beats 11.81 % of python submissions.
Runtime (ms)
Distribution (%)

40
50
60
70
80
90
100
110
120
2.5
5.0
Zoom area by dragging across this chart

Accepted Solutions Memory Distribution

13350
13100
13150
13200
13250
13300
13400
13450
13500
13550
13600
5
10
15
20
25
30
35
python
You are here!
Your memory usage beats 21.96 % of python submissions.
Memory (KB)
Distribution (%)

13350
13100
13150
13200
13250
13300
13400
13450
13500
13550
13600
10
20
30
Zoom area by dragging across this chart

Invite friends to challenge Valid Sudoku


Submitted Code: 0 minutes ago

Language: python

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
54
55
56
57
58
59
60
61
62
63
64
65
66
class Solution(object):
def isValidSudoku(self, board):
"""
:type board: List[List[str]]
:rtype: bool
"""
# check if row has duplicates
for i in range(0,len(board)):
seen = []
for j in range(0,len(board[i])):
if (board[i][j] not in seen and board[i][j] != '.'):
seen.append(board[i][j])
elif (board[i][j] in seen):
return False
seen = []
# transpose matrix
new_matrix = []
for i in range(0,len(board)):
row = []
for j in range(0,9):
row.append(board[j][i])
new_matrix.append(row)
# check if columns (transposed) have duplicates
for i in range(0,len(new_matrix)):
seen = []
for j in range(0,len(new_matrix[i])):
if (new_matrix[i][j] not in seen and new_matrix[i][j] != '.'):
seen.append(new_matrix[i][j])
elif (new_matrix[i][j] in seen):
return False
seen = []
# check if sub-grids have duplicates
r = 0
c = 0
while (r < 9 and c < 9):
square = []
for j in range(0,3):
for i in range(0,3):
if (board[r+i][c] in square):
return False
if (board[r+i][c] not in square
and board[r+i][c] != '.'):
square.append(board[r+i][c])
if (board[r+i][c+1] in square):
return False
if (board[r+i][c+1] not in square
and board[r+i][c+1] != '.'):
square.append(board[r+i][c+1])
if (board[r+i][c+2] in square):
return False
if (board[r+i][c+2] not in square
and board[r+i][c+2] != '.'):
square.append(board[r+i][c+2])
c += 3
square = []
c = 0
r += 3
return True
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX