1.题目描述
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)
将一个给定字符串根据给定的行数,以从上往下、从左到右进行 Z 字形排列。
比如输入字符串为 "PAYPALISHIRING"
行数为 3 时,排列如下:
1 | P A H N |
And then read line by line: "PAHNAPLSIIGYIR"
之后,你的输出需要从左往右逐行读取,产生出一个新的字符串,比如:"PAHNAPLSIIGYIR"
Write the code that will take a string and make this conversion given a number of rows:
1 | string convert(string s, int numRows); |
Example 1:
1 | Input: s = "PAYPALISHIRING", numRows = 3 |
Example 2:
1 | Input: s = "PAYPALISHIRING", numRows = 4 |
2.Solutions
1 | public static String convert(String s, int numRows) { |