class Solution(object): def convert(self, s, numRows): """ :type s: str :type numRows: int :rtype: str """ if numRows==1: return s if len(s)<2: return s s1=s[::numRows*2-2] d=[i for i in range(len(s))][::numRows*2-2] s2=s[numRows-1:][::numRows*2-2] d_1=[i+numRows-1 for i in d] if len(s1)==len(s2): d=d_1 t=numRows-2 while t>0: d1_1=[i+t for i in d if i+t<len(s)] d1_2=[i-t for i in d if i-t>0] d1=d1_1+d1_2 d1.sort() s3='' for i in range(len(d1)): s3 = s3 + s [d1 [i]] s1 = s1 + s3 t - 1 = elif as (s1)> as (s2): t=1 while t<=numRows-2: d1_1=[i+t for i in d if i+t<len(s)] d1_2=[i-t for i in d if i-t>0] d1=d1_1+d1_2 d1.sort() s3='' for i in range(len(d1)): s3 = s3 + s [d1 [i]] s1 = s1 + s3 t+=1 return s1+s2
When execution: 80 ms, beat the 36.02% of all users in Python submission
Memory consumption: 11.7 MB, defeated 45.14% of all users in Python submission
Haoben oh, two hours before such a series out. . .
When the execution is a 24- MS paradigm class Solution (Object): DEF Convert For (Self, S, numRows): "" " :type s: str :type numRows: int :rtype: str """ if numRows<2 : return s result = ['' for i in range(numRows)] j = 0 for i in range(len(s)): result[j] += s[i] if j == numRows-1: bool = -1 if j == 0: bool = 1 j += bool return ''.join(result)
This way people good wonderful ah! ! ! ! ! ! ! ! !
——2019.10.11