File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import java .util .ArrayList ;
2+ import java .util .List ;
3+
4+ /**
5+ * ×Öĸ´óСдȫÅÅÁÐ
6+ */
7+
8+ public class LetterCasePermutation0784 {
9+
10+ public static void main (String [] args ) {
11+ letterCasePermutation ("a1B2" );
12+ }
13+
14+ public static List <String > result = new ArrayList <>();
15+
16+ public static List <String > letterCasePermutation (String S ) {
17+
18+ backtrack (S , 0 , "" );
19+ for (String str : result ) {
20+ System .out .println (str );
21+ }
22+ return result ;
23+ }
24+
25+ private static void backtrack (String s , int start , String sb ) {
26+
27+ if (start >= s .length ()) {
28+ System .out .println (sb .toString ());
29+ return ;
30+ }
31+ char ch = s .charAt (start );
32+ if (Character .isLowerCase (ch )) {
33+ backtrack (s , start +1 , sb + ch );
34+ backtrack (s , start +1 , sb + Character .toUpperCase (ch ) );
35+ }else if (Character .isUpperCase (ch )) {
36+ backtrack (s , start +1 , sb + ch );
37+ backtrack (s , start +1 , sb + Character .toLowerCase (ch ));
38+ }else {
39+ backtrack (s , start +1 , sb + ch );
40+ }
41+ }
42+
43+ }
You can’t perform that action at this time.
0 commit comments