# Leetcode 6 - Zigzag conversion

Note:

• Iterate by ROWS.
• Create an array with numRows length.
• Each element is an empty string to store chars.
• Use a flag to denote the direction of moving. It’s either -1 or 1. 1 means moving down, and -1 means moving up.
• When the row is 0 or numRows - 1, flip the flag.

Question:

The string “PAYPALISHIRING“ is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)

And then read line by line: “PAHNAPLSIIGYIR

Write the code that will take a string and make this conversion given a number of rows:

Example:

Code:

Iterate by rows

Naive simulation with big space complexity