comefrom: <awangdev>Gray Code_2.java
code: public List<Integer> grayCode(int n) {
          List<Integer> rst = new ArrayList<Integer>();
          if (n < 0) {
          	return rst;
          }
          char[] bits = new char[n];
          for (int i = 0; i < bits.length; i++) {
          	bits[i] = '0';
          }
          String str = new String(bits);
          if (n == 0) {
              str = "0";
          }
          rst.add(Integer.parseInt(str, 2));
          int step = n - 1;
          boolean LR = true;
          int steps = (int)Math.pow(2, n) - 1;
          for (int i = 0; i < steps; i++) {
          	bits[step] = bits[step] == '0' ? '1' : '0';
          	str = new String(bits);
          	rst.add(Integer.parseInt(str, 2));
          	if (LR) {
          		step--;
          	} else {
          		step++;
          	}
          	if (step == (n - 1) || step == 0) {
          		LR = !LR;
          	}
          }
  
          return rst;
      }
masked: public List < Integer > var_1 ( int var_2 ) {
    List < Integer > var_5 = new ArrayList < Integer > ( ) ;
    if ( var_2 < 0 ) {
      return var_5 ;
    }
    char [ ] var_7 = new char [ var_2 ] ;
    for ( int var_8 = 0 ;
    var_8 < var_7 . length ;
    var_8 ++ ) {
      var_7 [ var_8 ] = '0' ;
    }
    String var_12 = new String ( var_7 ) ;
    if ( var_2 == 0 ) {
      var_12 = "0" ;
    }
    var_5 . add ( Integer . parseInt ( var_12 , 2 ) ) ;
    int var_18 = var_2 - 1 ;
    boolean var_24 = true ;
    int var_22 = ( int ) Math . pow ( 2 , var_2 ) - 1 ;
    for ( int var_8 = 0 ;
    var_8 < var_22 ;
    var_8 ++ ) {
      var_7 [ var_18 ] = var_7 [ var_18 ] == '0' ? '1' : '0' ;
      var_12 = new String ( var_7 ) ;
      var_5 . add ( Integer . parseInt ( var_12 , 2 ) ) ;
      if ( var_24 ) {
        var_18 -- ;
      }
      else {
        var_18 ++ ;
      }
      if ( var_18 == ( var_2 - 1 ) || var_18 == 0 ) {
        var_24 = ! var_24 ;
      }
    }
    return var_5 ;
  }
  