File tree Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Original file line number Diff line number Diff line change @@ -10,26 +10,23 @@ public static void main(String[] args) {
10
10
System .out .println (Arrays .toString (permutation ("abc" )));
11
11
}
12
12
13
- private static String [] permutation (String orginal ){
13
+ private static String [] permutation (String orginal ) {
14
14
System .out .println ("orginal = " + orginal );
15
15
ArrayList list = new ArrayList ();
16
- if (orginal .length () == 1 ){
16
+ if (orginal .length () == 1 ) {
17
17
System .out .println ("跳出递归 " + orginal );
18
18
return new String []{orginal };
19
- } else {
19
+ } else {
20
20
for (int i = 0 ; i < orginal .length (); i ++) {
21
21
String s = orginal .charAt (i ) + "" ;
22
- String result = "" ;
23
- String resultA = result + s ;
24
- System .out .println ("resultA: " + resultA + " + " + i );
22
+ System .out .println ("s: " + s + " + " + i );
25
23
//e.g bc时分别输出c b
26
24
String leftS = orginal .substring (0 , i ) + orginal .substring (i + 1 , orginal .length ());
27
25
System .out .println ("leftS: " + leftS );
28
26
//递归 permutation(leftS)
29
27
for (String element : permutation (leftS )) {
30
- result = resultA + element ;
31
- System .out .println ("递归: " + resultA + " + " + element + " = " + result );
32
- list .add (result );
28
+ System .out .println ("递归: " + s + " + " + element + " = " + (s + element ));
29
+ list .add (s + element );
33
30
}
34
31
}
35
32
System .out .println (Arrays .toString (list .toArray ()));
You can’t perform that action at this time.
0 commit comments