Practice/Oracle/Leetcode 6. Zigzag Conversion
CodingMust
Given a string and a number of rows, arrange the characters in a wave (zigzag) pattern that flows vertically down and diagonally up, then read the characters row by row from left to right to produce a transformed string.
The wave pattern works as follows: characters are placed vertically downward until reaching the bottom row, then diagonally upward until reaching the top row, and this pattern repeats.
For example, with the string "HELLO" and 3 rows:
The pattern looks like:
H O E L L L
Reading row by row: "HO" + "ELL" + "L" = "HOELL"
Example 1:
Input: s = "HELLOWORLD", numRows = 3 Output: "HOLELWRDLO" Explanation: H O R E L W L D L O Reading row by row: "HOR" + "ELWLD" + "LO" = "HORELWLDLO"
Example 2:
Input: s = "PAYPALISHIRING", numRows = 4 Output: "PINALSIGYAHRPI" Explanation: P I N A L S I G Y A H R P I Reading row by row gives: "PIN" + "ALSIG" + "YAHR" + "PI"
Example 3:
Input: s = "AB", numRows = 1 Output: "AB" Explanation: With only one row, no transformation occurs.