建设银行镇海支行网站,奉贤注册公司,网络科技公司是做什么的,seo优化知识总结写这题的时候没有啥DFS思路#xff0c;感觉还是DFS没刷明白#xff0c;还需要多提高 参考链接#xff1a; 【还得用回溯算法#xff01;| LeetCode#xff1a;17.电话号码的字母组合-哔哩哔哩】 https://b23.tv/oTuy71C
class Solution {public ListString lette…写这题的时候没有啥DFS思路感觉还是DFS没刷明白还需要多提高 参考链接 【还得用回溯算法| LeetCode17.电话号码的字母组合-哔哩哔哩】 https://b23.tv/oTuy71C
class Solution {public ListString letterCombinations(String digits) {ListString ansnew ArrayList();if(digitsnull||digits.length()0){return ans; }char[] chdigits.toCharArray();MapInteger,String mapnew HashMap();map.put(2,abc);map.put(3,def);map.put(4,ghi);map.put(5,jkl);map.put(6,mno);map.put(7,pqrs);map.put(8,tuv);map.put(9,wxyz);StringBuilder sbnew StringBuilder();dfs(ch,map,ans,sb,0);return ans;}public void dfs(char[] ch,MapInteger,String map,ListString ans,StringBuilder sb,int index){if(indexch.length){ans.add(sb.toString());// sb.setLength(0);return; }String curStr map.get(ch[index]-0);int ncurStr.length();for(int i0;in;i){sb.append(curStr.charAt(i));dfs(ch,map,ans,sb,index1);sb.deleteCharAt(sb.length()-1);}}}