public String convert(String s, int nRows) {

    if (nRows == 1) {
      return s;
    }

    List<List<Character>> alal = new ArrayList<List<Character>>();
    for (int i = 0 ; i < nRows ; i++) {
      alal.add(new ArrayList<Character>());
    }

    int curtRow = 0;
    boolean down = true;
    for (int i = 0 ; i < s.length() ; i++) {
      List<Character> al = alal.get(curtRow);
      al.add(s.charAt(i));

      if (down) {
        curtRow++;
        if (curtRow == nRows) {
          down = false;
          curtRow = nRows - 2;
        }
        continue;
      }

      if (!down) {
        curtRow--;
        if (curtRow == -1) {
          down = true;
          curtRow = 1;
        }
      }
    }

    StringBuffer sb = new StringBuffer();
    for (List<Character> al : alal) {
      for (Character ch : al) {
        sb.append(ch);
      }
    }

    return sb.toString();
  }