class Solution {
static String str[] = {
"", "","abc","def", "ghi","jkl", "mno","pqrs","tuv","wxyz"
};
/*
执行用时:
5 ms
, 在所有 Java 提交中击败了
19.26%
的用户
内存消耗:
41.4 MB
, 在所有 Java 提交中击败了
5.02%
的用户
*/
static List<String> ans = new ArrayList<>();
//爆搜
static void dfs(String digits, int u, String path) {
if(u == digits.length()) {
ans.add(path);
return;
}
for(char c: str[digits.charAt(u)-'0'].toCharArray()){
dfs(digits, u + 1, path+c);
}
}
public List<String> letterCombinations1(String digits) {
//清理一下上次测试数据
ans = new ArrayList<String>();
if(digits == null || digits.length() == 0) return ans;
dfs(digits, 0, "");
return ans;
17. 电话号码的字母组合
最新推荐文章于 2023-08-25 12:20:00 发布