标签:
public class Solution { public String convert(String s, int numRows) { if (numRows == 1) { return s; } int flg = 0; boolean dir = true; List<StringBuffer> list = new ArrayList<StringBuffer>(); for (int i = 0; i < numRows; i++) { list.add(new StringBuffer("")); } for (int i = 0; i < s.length(); i++) { list.get(flg).append(String.valueOf(s.charAt(i))); flg += dir ? 1 : -1; if (flg == numRows) { dir = !dir; flg -= 2; } else if (flg == -1) { dir = !dir; flg += 2; } } String result = ""; for (StringBuffer str : list) { result = result + str; } return result; } }
标签:
原文地址:http://www.cnblogs.com/vision-love-programming/p/5014914.html