本帖最后由 Miss_Allsunday 于 2017-6-17 08:26 编辑
6. ZigZag Conversion
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 NA P L S I I GY I RAnd 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".
字符串“PAYPALISHIRING"以zigzag模式写在制定数量的行像这样:(你可以用固定大小的字体去显示这个模式以取得更好的清晰度)
P A H N
A P L S I I G
Y I R
然后按行来读取:“PAHNAPLSIIGYIR“
写出一个函数用来接受输入的字符串以及转换的行数:
string convert(string text, int nRows);
convert("PAYPAlISHIRING", 3) 应该返回"PAHNAPLSIIGYIR".
你需要完成以下的函数:
char* convert(char* s, int numRows) {
}
这道题目的网址是:"https://leetcode.com/problems/zigzag-conversion/#/description".
|