LeetCode : ZigZag Conversion

 Question :- https://leetcode.com/problems/zigzag-conversion/

Solution :- 

class Solution:
    def convert(self, s: str, numRows: int) -> str:
        converted_str = ""
        start_index = 0
        index_num = numRows + numRows-1 -1

        for i in range(0,numRows):
            while(start_index<len(s)):
                converted_str+= s[start_index]
                start_index = start_index+index_num
            start_index = i
            index_num = index_num-2
            print(converted_str)
        return converted_str

s = "PAYPALISHIRING"
number = 3
ss = Solution()
print(ss.convert(s,number))

Comments