kucheasysa

Algoverse_adesh_16

Jun 12th, 2024
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. class Solution:
  2.     def convert(self, s: str, numRows: int) -> str:
  3.         if numRows == 1:
  4.             return s
  5.  
  6.         a = [""] * numRows
  7.        
  8.         x = 0
  9.         count = 1
  10.         for i in s:
  11.             a[x] += i
  12.             if x == 0:
  13.                 count = 1
  14.             elif x == numRows - 1:
  15.                 count = -1
  16.  
  17.             x += count
  18.            
  19.         ans = "".join(a)
  20.         return ans
Advertisement
Add Comment
Please, Sign In to add comment