題目:
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)
P A H N
A P L S I I G
Y I R
And then read line by line: "PAHNAPLSIIGYIR"
Write the code that will take a string and make this conversion given a number of rows
該字串"PAYPALISHIRING"以鋸齒形圖案在給定數量的行上書寫,如下所示:(您可能希望以固定字體顯示此圖案以獲得更好的可讀性)
然後逐行閱讀:"PAHNAPLSIIGYIR"
編寫程式碼,接受一個字串並根據給定的行數進行轉換
解題思路:
行數 = 1 → 直接回傳原字串。
用方向切換 (goingDown) 來模擬 zigzag 移動。
最後把所有行拼接輸出。