-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path17.txt
40 lines (36 loc) · 1.12 KB
/
17.txt
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
class Solution {
public ArrayList<String> output = new ArrayList<>();
HashMap<String, String> numbers = new HashMap<>() {
{
put("2", "abc");
put("3", "def");
put("4", "ghi");
put("5", "jkl");
put("6", "mno");
put("7", "pqrs");
put("8", "tuv");
put("9", "wxyz");
}
};
public void Combinations(String combination, String digits) {
if (digits.length() == 0) {
output.add(combination);
} else {
String digit = digits.substring(0, 1);
String letters = numbers.get(digit);
for (int i = 0; i < letters.length(); i++) {
String letter = letters.substring(i, i + 1);
Combinations(combination + letter, digits.substring(1));
}
}
}
public List<String> letterCombinations(String digits) {
if (digits.length() == 0) {
return new ArrayList<>();
} else {
Solution s = new Solution();
s.Combinations("", digits);
return s.output;
}
}
}