Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- List<String> outputList = new ArrayList<>();
- public List<String> letterCombinations(String digits) {
- Map<Integer, char[]> keypadMap = new HashMap<>();
- keypadMap.put(2, new char[] { 'a', 'b', 'c' });
- keypadMap.put(3, new char[] { 'd', 'e', 'f' });
- keypadMap.put(4, new char[] { 'g', 'h', 'i' });
- keypadMap.put(5, new char[] { 'j', 'k', 'l' });
- keypadMap.put(6, new char[] { 'm', 'n', 'o' });
- keypadMap.put(7, new char[] { 'p', 'q', 'r', 's' });
- keypadMap.put(8, new char[] { 't', 'u', 'v' });
- keypadMap.put(9, new char[] { 'w', 'x', 'y', 'z' });
- int i = 0;
- char temp[] = new char[digits.length()];
- printAll(temp, i, digits, keypadMap);
- return outputList;
- }
- public void printAll(char[] temp, int i, String digits, Map<Integer, char[]> keypadMap) {
- char[] charArray = digits.toCharArray();
- if (i > charArray.length - 1 && temp != null) {
- if (temp.length != 0) {
- outputList.add(new String(temp));
- }
- return;
- }
- for (int j = 0; j < keypadMap.get(charArray[i] - '0').length; j++) {
- temp[i] = keypadMap.get(charArray[i] - '0')[j];
- printAll(temp, i + 1, digits, keypadMap);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement