class Solution { public List < String > letterCasePermutation ( String S ) { List < StringBuilder > ans = new ArrayList ( ) ; ans . add ( new StringBuilder ( ) ) ; for ( char c : S . toCharArray ( ) ) { int n = ans . size ( ) ; if ( Character . isLetter ( c ) ) { for ( int i = 0 ; i < n ; ++ i ) { ans . add ( new StringBuilder ( ans . get ( i ) ) ) ; ans . get ( i ) . append ( Character . toLowerCase ( c ) ) ; ans . get ( n + i ) . append ( Character . toUpperCase ( c ) ) ; } } else { for ( int i = 0 ; i < n ; ++ i ) ans . get ( i ) . append ( c ) ; } } List < String > finalans = new ArrayList ( ) ; for ( StringBuilder sb : ans ) finalans . add ( sb . toString ( ) ) ; return finalans ; } }

class Solution ( object ) : NEW_LINE INDENT def letterCasePermutation ( self , S ) : NEW_LINE INDENT B = sum ( letter . isalpha ( ) for letter in S ) NEW_LINE ans = [ ] NEW_LINE for bits in xrange ( 1 << B ) : NEW_LINE INDENT b = 0 NEW_LINE word = [ ] NEW_LINE for letter in S : NEW_LINE INDENT if letter . isalpha ( ) : NEW_LINE INDENT if ( bits >> b ) & 1 : NEW_LINE INDENT word . append ( letter . lower ( ) ) NEW_LINE DEDENT else : NEW_LINE INDENT word . append ( letter . upper ( ) ) NEW_LINE DEDENT b += 1 NEW_LINE DEDENT else : NEW_LINE INDENT word . append ( letter ) NEW_LINE DEDENT DEDENT ans . append ( " " . join ( word ) ) NEW_LINE DEDENT return ans NEW_LINE DEDENT DEDENT


class Solution { public int [ ] sortArrayByParityII ( int [ ] A ) { int j = 1 ; for ( int i = 0 ; i < A . length ; i += 2 ) if ( A [ i ] % 2 == 1 ) { while ( A [ j ] % 2 == 1 ) j += 2 ; int tmp = A [ i ] ; A [ i ] = A [ j ] ; A [ j ] = tmp ; } return A ; } }

class Solution ( object ) : NEW_LINE INDENT def sortArrayByParityII ( self , A ) : NEW_LINE INDENT odd = 1 NEW_LINE for i in xrange ( 0 , len ( A ) , 2 ) : NEW_LINE INDENT if A [ i ] % 2 : NEW_LINE INDENT while A [ odd ] % 2 : NEW_LINE INDENT odd += 2 NEW_LINE DEDENT A [ i ] , A [ odd ] = A [ odd ] , A [ i ] NEW_LINE DEDENT DEDENT return A NEW_LINE DEDENT DEDENT