-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathSolution.py
36 lines (34 loc) · 825 Bytes
/
Solution.py
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
#coding=utf-8
__author__ = 'xuxuan'
class Solution(object):
def convert(self, s, numRows):
"""
:type s: str
:type numRows: int
:rtype: str
"""
if(s.__len__()==0):
return ''
if(numRows==1):
return s
n=2*numRows-2
ans=[]
for i in range(numRows):
a=[]
ans.append(a)
for i in range(s.__len__()):
k=i%n
if(k<numRows):
print k
ans[k].append(s[i])
else:
k-=numRows
ans[numRows-k-2].append(s[i])
str=''
for i in range(numRows):
for j in range(ans[i].__len__()):
str+=ans[i][j]
return str
s='A'
numRows=2
print Solution().convert(s,numRows)