<gouthampradhan>string_ZigZagConversion_1.java
public String convert(String s, int numRows) {
    if (s == null || s.length() <= numRows || numRows == 1) return s;
    List<String> list = new ArrayList<>();
    char[] A = new char[numRows];
    int direction = 1; 
    int n = 1;
    A[0] = s.charAt(0);
    for (int j = 1; j < numRows; ) {
      if (n >= s.length()) break;
      A[j] = s.charAt(n++);
      if (j == numRows - 1) {
        list.add(String.valueOf(A));
        A = new char[numRows];
        Arrays.fill(A, ' ');
        direction = 0;
      } else if (j == 0) {
        list.add(String.valueOf(A));
        A = new char[numRows];
        Arrays.fill(A, ' ');
        direction = 1;
      }
      j = direction == 1 ? j + 1 : j - 1;
    }
    if (!String.valueOf(A).trim().isEmpty()) list.add(String.valueOf(A));
    char[] arr = new char[s.length()];
    int k = 0;
    for (int j = 0; j < numRows; j++) {
      for (String aList : list) {
        if (aList.charAt(j) != ' ') arr[k++] = aList.charAt(j);
      }
    }
    return new String(arr).trim();
  }
public String var_0 ( String var_2 , int var_3 ) {
  if ( var_2 == null || var_2 . length ( ) <= var_3 || var_3 == 1 ) return var_2 ;
  List < String > var_9 = new ArrayList < > ( ) ;
  char [ ] var_10 = new char [ var_3 ] ;
  int var_11 = 1 ;
  int var_12 = 1 ;
  var_10 [ 0 ] = var_2 . charAt ( 0 ) ;
  for ( int var_15 = 1 ;
  var_15 < var_3 ;
  ) {
    if ( var_12 >= var_2 . length ( ) ) break ;
    var_10 [ var_15 ] = var_2 . charAt ( var_12 ++ ) ;
    if ( var_15 == var_3 - 1 ) {
      var_9 . add ( String . valueOf ( var_10 ) ) ;
      var_10 = new char [ var_3 ] ;
      Arrays . fill ( var_10 , ' ' ) ;
      var_11 = 0 ;
    }
    else if ( var_15 == 0 ) {
      var_9 . add ( String . valueOf ( var_10 ) ) ;
      var_10 = new char [ var_3 ] ;
      Arrays . fill ( var_10 , ' ' ) ;
      var_11 = 1 ;
    }
    var_15 = var_11 == 1 ? var_15 + 1 : var_15 - 1 ;
  }
  if ( ! String . valueOf ( var_10 ) . trim ( ) . isEmpty ( ) ) var_9 . add ( String . valueOf ( var_10 ) ) ;
  char [ ] var_23 = new char [ var_2 . length ( ) ] ;
  int var_24 = 0 ;
  for ( int var_15 = 0 ;
  var_15 < var_3 ;
  var_15 ++ ) {
    for ( String var_25 : var_9 ) {
      if ( var_25 . charAt ( var_15 ) != ' ' ) var_23 [ var_24 ++ ] = var_25 . charAt ( var_15 ) ;
    }
  }
  return new String ( var_23 ) . trim ( ) ;
}
