-
Notifications
You must be signed in to change notification settings - Fork 0
/
LeetCode_17_2.java
38 lines (35 loc) · 1005 Bytes
/
LeetCode_17_2.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
import java.security.PublicKey;
import java.util.ArrayList;
import java.util.List;
public class LeetCode_17_2 {
class Solution {
String[] str = {
"",
"",
"abc",
"def",
"ghi",
"jkl",
"mno",
"pqrs",
"tuv",
"wxyz"
};
List<String> list = new ArrayList<>();
public List<String> letterCombinations(String digits) {
if(digits.equals(""))
return list;
DFS(digits, 0, "");
return list;
}
public void DFS(String digits, int index, String s) {
if(index == digits.length()) {
list.add(s);
return;
}
String letter = str[digits.charAt(index) - '0'];
for (int i = 0; i < letter.length(); i++)
DFS(digits, index + 1, s + letter.charAt(i));
}
}
}