-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLetterCombinationsOfPhoneNumber.java
More file actions
39 lines (28 loc) · 1012 Bytes
/
LetterCombinationsOfPhoneNumber.java
File metadata and controls
39 lines (28 loc) · 1012 Bytes
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
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class LetterCombinationsOfPhoneNumber {
List<String> result = new ArrayList<>();
public static void solve(int idx, String digits, String temp) {
Map<String, String> numberMap = new HashMap<>();
numberMap.put("2", "abc");
numberMap.put("3", "def");
numberMap.put("4", "ghi");
numberMap.put("5", "jkl");
numberMap.put("6", "mno");
numberMap.put("7", "pqrs");
numberMap.put("8", "tuv");
numberMap.put("9", "wxyz");
String ch = String.valueOf(digits.charAt(idx));
String str = numberMap.get(ch);
StringBuilder tempBuilder = new StringBuilder(temp);
for (int i = 0; i < str.length(); i++) {
tempBuilder.append(str.charAt(i));
temp = tempBuilder.toString();
}
}
public List<String> letterCombinations(String digits) {
return result;
}
}