10秒之内,把蔡依林从这堆凤姐中找出来! (转)# Joke - 肚皮舞运动
e*e
1 楼
多谢lolhaha大牛指点,non-duplicate修订版如下。
client invoke: permute( new char[]{'a', 'b', 'c'}, 0 );
void permute(char[] perm, int level){
if ( level == perm.length ) {
System.out.println( new String( perm ) );
for ( int i = level, i < perm.length; i++ ) {
if ( level != i )
swap( perm, level, i );
permute( perm, level + 1 );
if ( level != i )
swap( perm, level, i );
}
}
void swap(char[] arr, int i, int j) {...}
client invoke: permute( new char[]{'a', 'b', 'c'}, 0 );
void permute(char[] perm, int level){
if ( level == perm.length ) {
System.out.println( new String( perm ) );
for ( int i = level, i < perm.length; i++ ) {
if ( level != i )
swap( perm, level, i );
permute( perm, level + 1 );
if ( level != i )
swap( perm, level, i );
}
}
void swap(char[] arr, int i, int j) {...}