Skip to content

Instantly share code, notes, and snippets.

@leearmee35
Last active August 22, 2016 12:12
Show Gist options
  • Save leearmee35/22d4f61c60fc442a1c15e48ba04c52e1 to your computer and use it in GitHub Desktop.
Save leearmee35/22d4f61c60fc442a1c15e48ba04c52e1 to your computer and use it in GitHub Desktop.
public class Solution {
private ArrayList<String> res = new ArrayList<String>();
public List<String> letterCombinations(String digits) {
int length = digits.length();
if(length==0) return res;
String[] str = {"", "", "abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
helper(0, digits, str, "");
return res;
}
public void helper(int index, String digits, String[] str, String curr){
if(index==digits.length()){
res.add(curr);
return;
}
String s1 = str[Integer.parseInt(""+digits.charAt(index))];
for(int i=0;i<s1.length();i++){
char ca = s1.charAt(i);
curr=curr+ca;
helper(index+1,digits,str,curr);
curr=curr.substring(0, curr.length()-1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment