public String convert(String s, int nRows) {
        List<List<Character>> charList = new ArrayList<>();
        for (int i = 0; i < nRows; i++)
            charList.add(new ArrayList<Character>());

        String res = "";
        if(s.trim().isEmpty() || nRows <= 1) return s;

        char[] chars = s.toCharArray();
        boolean isAscending = false;
        int pre = 0;
        charList.get(0).add(chars[0]);
        for (int i = 1; i < chars.length; i++) {
            if (pre + 1 == nRows || pre == 0) isAscending = !isAscending;
            int cur = isAscending ? ++pre : --pre;
            charList.get(cur).add(chars[i]);
        }

        for (List<Character> l : charList)
            for (Character c : l)
                res += c;
        return res;
    }