public String convert(String s, int numRows) {
        if (s == null || numRows <= 0) return "";

        StringBuilder[] sb = new StringBuilder[numRows];
        for (int i = 0; i < numRows; ++i) sb[i] = new StringBuilder();

        int i = 0;
        while (i < s.length()) {
            int row = 0;
            while (row < numRows && i < s.length()) {
                sb[row++].append(s.charAt(i++));
            }
            row = numRows - 2;
            while (row >= 1 && i < s.length()) {
                sb[row--].append(s.charAt(i++));
            }
        }

        for (i = 1; i < numRows; ++i) sb[0].append(sb[i]);
        return sb[0].toString();
    }