leetcode-6. Z 字形变换

class Solution {
	public String convert(String s, int numRows) {
		if (s.length() == 1)
			return s;
		StringBuffer[] sbs = new StringBuffer[numRows];
		for (int i = 0; i < sbs.length; ++i)
			sbs[i] = new StringBuffer();
		int i = 0;
		while (i < s.length()) {
			for (int j = 0; j < numRows && i < s.length(); ++j) {
				sbs[j].append(s.charAt(i++));
			}
			for (int j = numRows - 2; j > 0 && i < s.length(); --j) {
				sbs[j].append(s.charAt(i++));
			}
		}
		for (int j = 1; j < numRows; ++j)
			sbs[0].append(sbs[j]);
		return sbs[0].toString();
	}
}

 

    原文作者:Z字形编排问题
    原文地址: https://blog.csdn.net/qq_39370495/article/details/86681962
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞