-
Notifications
You must be signed in to change notification settings - Fork 13
/
Solution784.java
40 lines (32 loc) · 930 Bytes
/
Solution784.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package algorithm.leetcode;
import java.util.LinkedList;
import java.util.List;
/**
* @author: mayuan
* @desc: 字母大小写全排列
* @date: 2019/02/16
*/
public class Solution784 {
public List<String> letterCasePermutation(String S) {
List<String> ans = new LinkedList<>();
if (null == S) {
return ans;
}
dfs(ans, S.toCharArray(), 0);
return ans;
}
public void dfs(List<String> answer, char[] chs, int start) {
if (start == chs.length) {
answer.add(new String(chs));
return;
}
if ('0' <= chs[start] && chs[start] <= '9') {
dfs(answer, chs, start + 1);
} else {
chs[start] = Character.toLowerCase(chs[start]);
dfs(answer, chs, start + 1);
chs[start] = Character.toUpperCase(chs[start]);
dfs(answer, chs, start + 1);
}
}
}