classSolution{ public String convert(String s, int numRows){ if (s == null || s.length() <= 0 || numRows <= 1) { return s; } String[] arr = new String[numRows]; Arrays.fill(arr,""); int cycle = 2 * numRows - 2; int position = 0; int mod = 0; for (char c : s.toCharArray()) { mod = position % cycle; if (mod < numRows) { arr[mod] += c; }else{ arr[cycle - mod] += c; } position++; } StringBuilder re = new StringBuilder(); for(String line : arr) { re.append(line); } return re.toString(); } }