Submission Detail

25 / 25 test cases passed.
Status:

Accepted

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

Accepted Solutions Runtime Distribution

0
5
10
15
20
25
30
35
5
10
15
python
You are here!
Your runtime beats 82.72 % of python submissions.
Runtime (ms)
Distribution (%)

0
5
10
15
20
25
30
35
5
10
15
Zoom area by dragging across this chart

Accepted Solutions Memory Distribution

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

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

Invite friends to challenge Spiral Matrix


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
67
68
69
70
71
72
73
74
75
76
77
class Solution(object):
def spiralOrder(self, matrix):
"""
:type matrix: List[List[int]]
:rtype: List[int]
"""
if (len(matrix) == 1):
return matrix[0]
if (len(matrix[0]) == 1):
spiral = []
for i in range(0,len(matrix)):
spiral.append(matrix[i][0])
return spiral
m = len(matrix) # num of rows
n = len(matrix[0]) # num of columns
r = 0
c = 0
count = 0
spiral = []
while ((0 + count) < (n - count)
and (0 + count) < (m - count)):
right = False
down = False
left = False
up = False
# right
while (c < n - count):
spiral.append(matrix[r][c])
c += 1
right = True
r += 1
if (right == True):
c -= 1
else:
break
# down
while (r < m - count):
spiral.append(matrix[r][c])
r += 1
down = True
c -= 1
if (down == True):
r -= 1
else:
break
# left
while (c >= 0 + count):
spiral.append(matrix[r][c])
c -= 1
left = True
if (left == True):
c += 1
else:
break;
r -= 1
# up
while (r > 0 + count):
spiral.append(matrix[r][c])
r -= 1
up = True
c += 1
if (up == True):
r += 1
else:
break;
count += 1
return spiral
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX