Skip to content

Commit db61d34

Browse files
author
ChienkuChen
committed
Add 784
1 parent fc44e54 commit db61d34

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package _784;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
class Solution {
7+
public List<String> letterCasePermutation(String S) {
8+
if (S == null)
9+
return new ArrayList<>();
10+
11+
List<String> result = new ArrayList<>();
12+
helper(S, 0, "", result);
13+
14+
return result;
15+
}
16+
17+
private void helper(String S, int start, String tmp, List<String> result) {
18+
if (start >= S.length()) {
19+
result.add(tmp);
20+
return;
21+
}
22+
23+
helper(S, start + 1, tmp + S.charAt(start), result);
24+
25+
if (Character.getType(S.charAt(start)) == Character.LOWERCASE_LETTER) {
26+
helper(S, start + 1, tmp + Character.toUpperCase(S.charAt(start)), result);
27+
} else if (Character.getType(S.charAt(start)) == Character.UPPERCASE_LETTER) {
28+
helper(S, start + 1, tmp + Character.toLowerCase(S.charAt(start)), result);
29+
}
30+
}
31+
32+
public static void main(String[] args) {
33+
System.out.println(new Solution().letterCasePermutation("a1b2"));
34+
System.out.println(new Solution().letterCasePermutation("3z4"));
35+
System.out.println(new Solution().letterCasePermutation("12345"));
36+
}
37+
}

0 commit comments

Comments
 (0)