Last active
June 4, 2020 04:44
-
-
Save vishal-keshav/48ec95a1ca236b51c2ca97d77fd63db6 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(object): | |
def convert(self, s, numRows): | |
if numRows == 1: return s | |
arr_of_arr = [[] for i in range(numRows)] | |
running_index, direction = 0, 1 | |
for c in s: | |
arr_of_arr[running_index].append(c) | |
running_index += direction | |
if running_index>=numRows: | |
running_index, direction = numRows-2, -1 | |
if running_index<0: | |
running_index, direction = 1, 1 | |
return ''.join(sum(arr_of_arr, [])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment