wordpress怎么删除预建网站,网站排名优化软件电话,wordpress批量下载外链图片,从网络安全角度考量_写出建设一个大型电影网站规划方案17.电话号码的字母组合
给定一个仅包含数字 2-9 的字符串#xff0c;返回所有它能表示的字母组合。答案可以按 任意顺序 返回。
给出数字到字母的映射如下#xff08;与电话按键相同#xff09;。注意 1 不对应任何字母。 示例 1#xff1a;
输入#xff1a;digits 返回所有它能表示的字母组合。答案可以按 任意顺序 返回。
给出数字到字母的映射如下与电话按键相同。注意 1 不对应任何字母。 示例 1
输入digits 23
输出[ad,ae,af,bd,be,bf,cd,ce,cf]示例 2
输入digits
输出[]示例 3
输入digits 2
输出[a,b,c]提示
0 digits.length 4digits[i] 是范围 [2, 9] 的一个数字。
思路
本题和前几题回溯不太一样前几题是要把int类型放进答案这题是将字符组成字符串然后放入答案其实没有什么不同我使用了StringBuilder来传递字符串和添加/删除字符但是这样的时间不知道是不是最佳的。 class Solution {public ListString letterCombinations(String digits) {ListString resnew ArrayList();if(digits.length()0){return res;}StringBuilder ansnew StringBuilder();backtracking(0,digits,ans,res);return res;}public void backtracking(int depth,String digits,StringBuilder ans,ListString res){if(depthdigits.length()){res.add(ans.toString());return;}int kCharacter.getNumericValue(digits.charAt(depth));String temp;switch(k){case 2:tempabc;break;case 3:tempdef;break;case 4:tempghi;break;case 5:tempjkl;break;case 6:tempmno;break;case 7:temppqrs;break;case 8:temptuv;break;case 9:tempwxyz;break;}for(int i0;itemp.length();i){ans.append(temp.charAt(i));backtracking(depth1,digits,ans,res);ans.deleteCharAt(ans.length()-1);}}}
时间复杂度O(3m×4n)m是对应三个字母的数字个数234568n是对应四个字母的数字个数79
空间复杂度Omn递归调用层数最大为mn