###### Easy-题目61：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   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”.

nRows=3时：

nRows=4时：

public class Solution {
public String convert(String s, int numRows)
{
if(numRows==1)
return s;
else    {
int step1=(numRows-1)*2;
int step2=0;

for(int i=0;i<numRows;i++)  {
String line="";
int j=i;
boolean isStep1=true;
while(j<s.length()) {
if(step2==0)    {
line+=s.charAt(j);
j+=step1;
}
else if(step1==0) {
line+=s.charAt(j);
j+=step2;
}
else    {
line+=s.charAt(j);
if(isStep1)
j+=step1;
else
j+=step2;
isStep1=!isStep1;
}
}
step1-=2;
step2+=2;
}
}
}
}

33ms,beats 25.35%,众数8ms,15.13%
cmershen的碎碎念：

#### LeetCode 6 ZigZag Conversion (C,C++,Java,Python)

2015-05-06 22:55:25

#### Leetcode_6_ZigZag Conversion

2014-11-23 09:45:55

#### 6. ZigZag Conversion Leetcode Python

2015-01-28 02:21:14

#### [Leetcode]6. ZigZag Conversion @python

2016-01-13 00:32:16

#### 【LeetCode】ZigZag Conversion 解题报告

2014-10-26 16:49:26

#### leetcode 6 ZigZag Conversion C++

2016-06-28 10:52:31

#### 【LeetCode】LeetCode——第6题：ZigZag Conversion

2016-04-19 10:09:57

#### LeetCode-6. ZigZag Conversion (JAVA)（之字形转换）

2017-04-17 09:41:03

#### 【python】【leetcode】【算法题目6—ZigZag Conversion】

2016-11-26 15:44:31

#### [LeetCode][6]ZigZag Conversion解析与特殊解法 -Java实现

2016-06-06 14:29:53

## 不良信息举报

Easy-题目61：6. ZigZag Conversion