您的位置:首页 > 其它

leetcode - ZigZag Conversion

2015-05-17 23:07 316 查看
转自:/article/6347759.html

题目:

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:
string convert(string text, int nRows);

convert("PAYPALISHIRING", 3)
should
return
"PAHNAPLSIIGYIR"


Zigzag:即循环对角线结构(
0816
1791517
26101418
35111319
41220


nRows行,声明nRows个字符串,每个字符串存储自己行的字符

向下循环:nRows

斜角线向上循环: 从nRows-2 开始,1 结束 (减去首尾两个端点)

重复

...

  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: