python solution


  • 0
    X

    class Solution(object):
    def convert(self, s, numRows):
    flag =0
    lens = len(s)
    if lens <=1:
    return s
    if numRows ==1:
    return s
    if numRows >=lens:
    return s
    lists =[]
    for i in range(numRows):
    listname = s+str(i)
    listname = []

            lists.append(listname)
    
        start =0
        end = numRows-1
        for i in s:
           
            if start <end:
                lists[start].append(i)
                start = start+1
                continue   
            elif start==end:
                lists[start].append(i)   
                
                if end==0:
                    end=numRows-1
                    start = start+1
                else:
                    start = start -1
                    end=0
                
            elif start >end:
                lists[start].append(i)
                start = start-1
           
        listword = []
        for i in range(len(lists)):
            listword = listword+lists[i]
        
        listwordres = ''.join(listword)
       
        return listwordres

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.