simplest python solution


  • 0
    A
    class Solution(object):
        def convert(self, s, numRows):
            """
            :type s: str
            :type numRows: int
            :rtype: str
            """
            
            if numRows==1 :  return s
            final_list = [[] for i in range(numRows)]
            word_c=0
            index=0
            
            while word_c < len(s):
                        if index == 0:  flag =1
                        if index == numRows-1 : flag=2    
                        final_list[index].append(s[word_c])
                        word_c+=1
                        if flag ==1 : index +=1
                        else : index-=1
            return "".join(["".join(i) for i in final_list]) 
    

Log in to reply
 

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