蔡晓建

• 首行和尾行

• 其他行

# 参考源码

``````public class Solution {
public String convert(String s, int numRows) {
if (numRows <= 1) {
return s;
}

int len = s.length();
char[] cs = new char[len];

int newpos = 0;
for (int row = 0; row < numRows; row++) {
//first or last row
if (row == 0 || row == numRows - 1) {
int pos = row;
while (pos < len && newpos < len) {
cs[newpos] = s.charAt(pos);
newpos++;
pos += 2 * (numRows - 1);
}
} else {
int pos = row;
int dir = 0;
while (pos < len && newpos < len) {
cs[newpos] = s.charAt(pos);
newpos++;
if (dir == 0) {
pos += 2 * (numRows - 1) - 2 * row;
dir = 1;
} else if (dir == 1) {
pos += 2 * row;
dir = 0;
}
}
}
}
return new String(cs);
}
}
``````

### 蔡晓建

[leetcode] 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 ......

jdflyfly
2014/06/24
0
0
LeetCode-ZigZag conversion

Zigzag Conversion Solution mind path We can notice that it has a pattern. Every zigzag pattern is composed by a list of structures.As of example 2, Let's write the zigzag positi......

Quan全
07/10
0
0
Leetcode 6. ZigZag Conversion

SnailTyan
09/17
0
0
6. ZigZag Conversion - LeetCode

LeetCode Problems Solutions question description: 问题描述 //问题截图： origin.png //锯齿状 sawtooth.png Thinking 你们可以自己先考虑一下。 solution with java - Java解决方案 solu......

2017/08/23
0
0
leetcode算法题解(Java版)-2-最长回文子串

kissjz
04/28
0
0

WALK_MAN

2
0
《大漠烟尘》读书笔记及读后感文章3700字

《大漠烟尘》读书笔记及读后感文章3700字： 在这个浮躁的社会里，你有多久没有好好读完一本书了？ 我们总觉得自己和别人不一样，所以当看到别人身上的问题时，很少有“反求诸己”，反思自己。...

3
0

em_aaron

3
0

3
0
Terraform配置文件（Terraform configuration）

Terraform配置文件 翻译自Terraform Configuration Terraform用文本文件来描述设备、设置变量。这些文件被称为Terraform配置文件,以.tf结尾。这一部分将讲述Terraform配置文件的加载与格式。...

buddie

5
0