-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17.java
More file actions
21 lines (20 loc) · 778 Bytes
/
17.java
File metadata and controls
21 lines (20 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class Solution {
public List<String> letterCombinations(String digits) {
String[] maps = {"0","1","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
LinkedList<String> ans = new LinkedList();
if (digits == null || digits.length() == 0){return ans;}
int len = digits.length();
ans.push("");
for (int i = 0; i < len; i++){
while (ans.peek().length() == i){
String dealing = ans.remove();
String map = maps[Character.getNumericValue(digits.charAt(i))];
int lenMap = map.length();
for (int j = 0; j < lenMap; j++){
ans.add(dealing+map.charAt(j));
}
}
}
return ans;
}
}