Skip to content

Jeffma0103/Zigzag-Conversion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Zigzag-Conversion (medium)

Solution of Zigzag Conversion

給定一個字串 s 及指定行數 numRows, 將字串 s 轉為 numRows 行的 Z 字型, 並輸出結果。

ex:

Input:
s = "PAYPALISHIRING" , numRows = 3

Output:
"PAHNAPLSIIGYIR"

P     A     H     N
A   P   L   S   I   I   G
Y     I     R

Workaround   1

想法
give a s = "PAYPALISHIRING" , numRows = 4
written in a zigzag pattern is "PINALSIGYAHRPI"

截圖 2024-05-14 下午8 47 11

可以發現 :
s   依照以下排序來進行改寫為   zigzag pattern
012321 | 012321 | 01

0 1 2 3
PIN ALSIG YAHR PI

再依照 "0" + "1" + "2" + "3" 的方式即可得到轉換後的字串

About

Solution of Zigzag Conversion

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages