<qiyuangong>784_Letter_Case_Permutation_2.java
public List<String> letterCasePermutation(String S) {
        int B = 0;
        for (char c: S.toCharArray())
            if (Character.isLetter(c))
                B++;

        List<String> ans = new ArrayList();

        for (int bits = 0; bits < 1<<B; bits++) {
            int b = 0;
            StringBuilder word = new StringBuilder();
            for (char letter: S.toCharArray()) {
                if (Character.isLetter(letter)) {
                    if (((bits >> b++) & 1) == 1)
                        word.append(Character.toLowerCase(letter));
                    else
                        word.append(Character.toUpperCase(letter));
                } else {
                    word.append(letter);
                }
            }

            ans.add(word.toString());
        }

        return ans;

    }
public List < String > var_1 ( String var_2 ) {
  int var_4 = 0 ;
  for ( char var_6 : var_2 . toCharArray ( ) ) if ( Character . isLetter ( var_6 ) ) var_4 ++ ;
  List < String > var_11 = new ArrayList ( ) ;
  for ( int var_12 = 0 ;
  var_12 < 1 << var_4 ;
  var_12 ++ ) {
    int var_14 = 0 ;
    StringBuilder var_16 = new StringBuilder ( ) ;
    for ( char var_17 : var_2 . toCharArray ( ) ) {
      if ( Character . isLetter ( var_17 ) ) {
        if ( ( ( var_12 >> var_14 ++ ) & 1 ) == 1 ) var_16 . append ( Character . toLowerCase ( var_17 ) ) ;
        else var_16 . append ( Character . toUpperCase ( var_17 ) ) ;
      }
      else {
        var_16 . append ( var_17 ) ;
      }
    }
    var_11 . add ( var_16 . toString ( ) ) ;
  }
  return var_11 ;
}
