-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathZigzag-Conversion.py
More file actions
31 lines (31 loc) · 820 Bytes
/
Zigzag-Conversion.py
File metadata and controls
31 lines (31 loc) · 820 Bytes
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
#! /usr/bin/env python
#! -*- coding=utf-8 -*-
# Date: 8/12/19
# Author: Bryce
class Solution(object):
def convert(self, s, numRows):
"""
:type s: str
:type numRows: int
:rtype: str
"""
n = len(s)
res = ""
if numRows == 1:
return s
m = 2 * numRows -2
for i in range (numRows):
if (i == 0 or i == numRows-1):
for j in range (i,n,m):
res += s[j]
else:
j = i
k = 2*numRows -i -1 -1
while (j < n or k < n ):
if j < n:
res += s[j]
if k < n:
res += s[k]
j += m
k += m
return res