Skip to content

Instantly share code, notes, and snippets.

@vishal-keshav
Last active June 4, 2020 04:44
Show Gist options
  • Save vishal-keshav/48ec95a1ca236b51c2ca97d77fd63db6 to your computer and use it in GitHub Desktop.
Save vishal-keshav/48ec95a1ca236b51c2ca97d77fd63db6 to your computer and use it in GitHub Desktop.
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