/*
Input: s = "PAYPALISHIRING",?
numRows = 4
Output: "PINALSIGYAHRPI"
注意:一定判斷numrows 長度 是1的話 直接return媒吗;
建立一個(gè)指向性的Boolean值名字為upAndDown 判斷 +1 或者 -1蜻拨;
for循環(huán) 每次到第一行或者最后一行 就翻轉(zhuǎn)upAndDown的值;
*/
class Solution {
public String convert(String s, int numRows) {?
? ? ? ?if(numRows == 1) return s;?
? ? ? ?ArrayList rows = new ArrayList<> ();
? ? ? ? int n = Math.min(s.length(), numRows);
? ? ? ? for(int i = 0; i < n; i++){
? ? ? ? ? ? rows.add(new StringBuilder());
? ? ? ? }
? ? ? ? Boolean upAndDown = false;
? ? ? ? int curRow = 0;
? ? ? ? for(int i = 0; i < s.length(); i++){
? ? ? ? ? ? rows.get(curRow).append(s.charAt(i));
? ? ? ? ? ? if(curRow == 0 || curRow == numRows - 1) {
? ? ? ? ? ? ? ? upAndDown = !upAndDown;
? ? ? ? ? ? }? ?
? ? ? ? ? ? curRow += upAndDown ? (+1) : (-1);
? ? ? ? }
? ? ? ? StringBuilder result = new StringBuilder();
? ? ? ? for(StringBuilder b : rows){
? ? ? ? ? ? result.append(b);
? ? ? ? }
? ? ? ? return result.toString();
? ? }
}