public String convert(String s, int nRows) {
        if (s == null || nRows < 1) {
            return null;
        };
        if (nRows == 1) {
            return s;
        }

        List<StringBuilder> lines = new LinkedList<>();
        for (int i = 0; i < nRows; i ++) {
            lines.add(new StringBuilder());
        }

        for (int i = 0; i < s.length(); i ++) {
            char c = s.charAt(i);

            int mod = i % (nRows * 2 - 2);

            if (mod == 0) {
                lines.get(0).append(c);
            } else if (mod == nRows - 1) {
                lines.get(nRows - 1).append(c);
            } else if (mod < nRows - 1) {
                lines.get(mod).append(c);
            } else {
                lines.get(nRows * 2 - 2 - mod).append(c);
            }
        }

        StringBuilder result = new StringBuilder();
        for (StringBuilder builder : lines) {
            result.append(builder);
        }

        return result.toString();
    }