From 541aa2a41566abbf65ff0ed0b6db1a0d5acecd61 Mon Sep 17 00:00:00 2001 From: Ivan Lazunin Date: Thu, 8 Oct 2020 13:11:20 +0300 Subject: [PATCH] Added Solution to Problem 6 ZigZag Conversion --- LeetCode/0006_ZigZag_Conversion.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 LeetCode/0006_ZigZag_Conversion.py diff --git a/LeetCode/0006_ZigZag_Conversion.py b/LeetCode/0006_ZigZag_Conversion.py new file mode 100644 index 0000000..7b10e40 --- /dev/null +++ b/LeetCode/0006_ZigZag_Conversion.py @@ -0,0 +1,26 @@ +import math + +class Solution: + def convert(self, s: str, numRows: int) -> str: + + if numRows == 1: + return s + + lenSec = numRows*2 - 2 + arr = ['' for i in range(numRows)] + idy = 0 + + for i in range(len(s)): + iSeq = i % lenSec + arr[idy] += s[i] + + if iSeq < numRows-1: + idy += 1 + else: + idy -= 1 + + s_out = '' + for i in arr: + s_out += i + + return s_out \ No newline at end of file