标签:new 需要 简洁 相同 alt col 不同的 str http
class Solution { public List<String> letterCombinations(String digits) { List<String> list=new ArrayList(); if(digits.length()==0)return list; String s=""; backTrace(s,digits,0,list); return list; } void backTrace(String s,String digits,int len,List<String> list){ String[] a={"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; if(len==digits.length()){ list.add(s); return; } String chars=a[digits.charAt(len)-‘0‘]; for(int i=0;i<chars.length();i++){ //如果这里写的是s=s+chars.charAt(i),而不是写在backTrace()中,会造成字符串增长,因为回溯的每一个结果都与其他结果无关 backTrace(s+chars.charAt(i),digits,len+1,list); } } }
标签:new 需要 简洁 相同 alt col 不同的 str http
原文地址:https://www.cnblogs.com/patatoforsyj/p/9639799.html