题目:


提交01:
1 class Solution {
2
3 public String convert(String s, int numRows) {
4 int length = 2*numRows-2;
5 if(numRows==1||s.equals("")||s.length()<=numRows){
6 return s;
7 }
8 int loop = s.length()/length;
9 StringBuilder str = new StringBuilder();
10
11 for(int i=0;i<numRows;i++){
12 str.append(s.charAt(i));
13 if(i!=0&&i!=numRows-1&&length-i<s.length()) {
14 str.append(s.charAt(length - i));
15 }
16
17
18 for(int k=1;k<loop+1;k++){
19 if(length*k+i<s.length()){
20 str.append(s.charAt(length*k+i));
21 }
22
23 if(i!=0&&i!=numRows-1&&length*(k+1)-i<s.length()){
24 str.append(s.charAt(length*(k+1)-i));
25 }
26
27 }
28 }
29 return str.toString();
30 }
31
32 }

代码有点乱,很多地方需要改进