Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
47 lines (47 loc) · 1.65 KB

File metadata and controls

47 lines (47 loc) · 1.65 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
41
42
43
44
45
46
47
public class App {
public static void main(String[] args) throws Exception {
String s="23";
letterCombinations(s);
}
public static Map<Integer,String> initMap (){
Map<Integer,String> initMap = new HashMap<>();
initMap.put(2, "abc");
initMap.put(3, "def");
initMap.put(4, "ghi");
initMap.put(5, "jkl");
initMap.put(6, "mno");
initMap.put(7, "pqrs");
initMap.put(8, "tuv");
initMap.put(9, "wxyz");
return initMap;
}
public static List<String> letterCombinations(String digits) {
List<String> list = new ArrayList<>();
Map<Integer, String> initMap = initMap();
char[] charArray = digits.toCharArray();
List<Integer> cIntegers=new ArrayList<>();
for (int i = 0; i < charArray.length; i++) {
cIntegers.add((int) charArray[i]);
}
if (cIntegers.isEmpty()) {
return list;
}
for (int i = 0; i < cIntegers.size(); i++) {
list=spand(list, cIntegers.get(i), initMap);
}
return list;
}
private static List<String> spand(List<String> result,Integer cInteger, Map<Integer, String> initMap) {
String strings = initMap.get(cInteger);
char[] charArray = strings.toCharArray();
List<String> list = new ArrayList<>();
for (int i = 0; i < charArray.length; i++) {
for (int j = 0; j < result.size(); j++) {
StringBuilder sb = new StringBuilder(result.get(i));
sb.append(charArray[i]);
result.set(i, sb.toString());
}
}
return result;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.