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: "PAHNAPLSII…
ZigZag Conversion 看了三遍题目才懂,都有点怀疑自己是不是够聪明... 就是排成这个样子啦,然后从左往右逐行读取返回. 这题看起来很简单,做起来,应该也很简单. 通过位置计算行数: P I N A L S I G Y A H R P I 0,0 1,1 2,2 3,3 4,2 5,1 6,0 (期望) 用简单的先思考: P A H N A P L S I I G Y I R 0,0 1,1 2,2 3,3 4,0 %4 (3+1)可以解决正常的 3,1(期望) 特殊的3(2行2排…
题意:将字符串排成Z字形. PAHNAPLSIIGYIR 如果是5的话,是这样排的 P     I AP   YR H L G N  SI A    I 于是,少年少女们,自己去找规律吧 提示:每个Z字形的字符串和原字符串的每个字母的位子一一映射 class Solution { public: string convert(string s, int numRows) { string t = s; ) return t; ; ; i < s.size(); i += * numRows -…
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) P A H N A P L S I I G Y I R And then read line by line: "…
这道题是LeetCode里的第6道题. 题目要求: 将一个给定字符串根据给定的行数,以从上往下.从左到右进行 Z 字形排列. 比如输入字符串为 "LEETCODEISHIRING" 行数为 3 时,排列如下: L C I R E T O E S I I G E D H N 之后,你的输出需要从左往右逐行读取,产生出一个新的字符串,比如:"LCIRETOESIIGEDHN". 请你实现这个将字符串进行指定行数变换的函数: string convert(string s…
problem: 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: "P…
题目: 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: "PAHNAP…
原题链接 把字符串按照 ↓↗↓……的顺序,排列成一个 Z 形,返回 从左到右,按行读得的字符串. 思路: 建立一个二维数组来按行保存字符串. 按照 ↓↗↓……的方向进行对每一行加入字符. 太慢了这个解法,Runtime: 96 ms, faster than 3.61% of C++. class Solution { public: string convert(string s, int numRows) { ) return s; string res; string zigZag[num…
问题描述: 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: "PAHN…
题目: 把一个字符串按照Z型排列后打印出来,例如 "PAYPALISHIRING" 重新排列后为3行,即 P A H N A P L S I I G Y I R 那么输出为"PAHNAPLSIIGYIR" 解法: 细节实现题,假如重新排列为5行,那么排列后的下标分布应该为 0  8   16 24 1 7 9   15   17 23 2 6 10 14 18 22 3 5 11 13 19 21 4  12 20 可以看出规律,输出为5行的时候,每两个完整列之间的…