Submission Detail

1157 / 1157 test cases passed.
Status:

Accepted

Runtime: 149 ms
Memory Usage: 13.6 MB
Submitted: 2 weeks ago
loading
Runtime Error Message:
Last executed input:
Input:
Output:
Expected:

Accepted Solutions Runtime Distribution

100
200
300
400
500
600
700
800
900
1000
1100
1200
1.0
2.0
3.0
4.0
python
You are here!
Your runtime beats 17.02 % of python submissions.
Runtime (ms)
Distribution (%)

100
200
300
400
500
600
700
800
900
1000
1100
1200
1
2
3
4
Zoom area by dragging across this chart

Accepted Solutions Memory Distribution

13500
14000
14500
15000
15500
16000
16500
17000
17500
18000
18500
19000
19500
20000
5
10
15
20
25
30
python
You are here!
Your memory usage beats 66.07 % of python submissions.
Memory (KB)
Distribution (%)

13500
14000
14500
15000
15500
16000
16500
17000
17500
18000
18500
19000
19500
20000
10
20
30
Zoom area by dragging across this chart

Invite friends to challenge Zigzag Conversion


Submitted Code: 2 weeks 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
class Solution(object):
def convert(self, s, numRows):
"""
:type s: str
:type numRows: int
:rtype: str
"""
word = []
ind = 0
# offset alternates for calculating indices
off = 0
# iterate through rows
for i in range(0,numRows):
off = 0
if (i+1 > len(s)):
return "".join(word)
word.append(s[ind])
if (i == 0 or i == numRows-1 and len(s) > 1):
if (numRows == 1):
if (len(s) > 1):
ind += 1
while (ind < len(s)):
word.append(s[ind])
ind += 1
else:
while (ind+(2*numRows)-2 < len(s)):
ind += 2*numRows-2
word.append(s[ind])
else:
while ((off == 0 and ind+(2*numRows)-(2*i)-2 < len(s)) or
(off == 1 and ind+2*i < len(s))):
if (off == 0):
if (ind+(2*numRows)-(2*i)-2 < len(s)):
ind += 2*numRows - 2*i - 2
word.append(s[ind])
off = 1
continue
if (off == 1):
if (ind + 2*i < len(s)):
ind += 2*i
word.append(s[ind])
off = 0
continue
ind = i + 1
the_word = "".join(word)
print(word)
return the_word
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX