Created
September 17, 2019 23:39
-
-
Save DataSolveProblems/6c410d33d83473a57cb218d2c74cc838 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def convert(self, s: str, numRows: int) -> str: | |
if numRows == 1: | |
return s | |
zigzag = [[] for _ in range(numRows)] | |
row = 0 | |
direction = -1 | |
for c in s: | |
zigzag[row].append(c) | |
if row == 0 or row == numRows - 1: | |
direction = -direction | |
row += direction | |
return ''.join([c for r in zigzag for c in r]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment