Leetcode17电话号码的组合

思路:用字典的形式保存号码的映射,实际组合是前一个数字串的组合加上后面一个数字的所有可能组合

python 复制代码
answer_dict={'2':['a','b','c'],'3':['d','e','f'],'4':['g','h','i'],'5':['j','k','l'],'6':['m','n','o'],'7':['p','q','r','s'],
             '8':['t','u','v'],'9':['w','x','y','z']}
class Solution:
    def letterCombinations(self, digits: str) -> list[str]:
        digits=digits.replace('1','')
        if not digits:
           return [] 
        digits_list=list(digits)
        answer_list=answer_dict[digits_list[0]][:]
        for digit in digits_list[1:]:
            current_answer=[]
            for each_answer in answer_list:
                for each_char in answer_dict[digit]:
                    current_answer.append(each_answer+each_char)
            answer_list=current_answer
        print(answer_list)
        return answer_list
相关推荐
为啥全要学9 小时前
自注意力中随着根号dk的增大,qk点积的方差为什么也会增大
python·深度学习
来两个炸鸡腿10 小时前
【Datawhale2607】llm-algo-leetcode task02 基础算子
人工智能·python·大模型
庵中十三居士10 小时前
【纯AI无人工修改】AI Agent从0到1实战:50行Python手写核心循环,一次看懂所有Agent框架的底层逻辑
开发语言·人工智能·python
天天爱吃肉821811 小时前
# 商用车多体动力学整车仿真学习笔记(开篇总览)
人工智能·笔记·python·功能测试·学习·汽车
Allen说改装11 小时前
2025 APAxpo佛山改装展的展出规模达到了多少平方米?
人工智能·python
aqi0011 小时前
15天学会AI应用开发(十四)搭建LangChain的开发环境
人工智能·python·大模型·ai编程·ai应用
想会飞的蒲公英12 小时前
词袋模型与 CountVectorizer:文本也可以做特征表
人工智能·python·机器学习
LadenKiller12 小时前
近期量化工具推荐,问题位置比功能清单更重要
人工智能·python
Hesionberger12 小时前
LeetCode406:重建身高队列精髓解析
开发语言·数据结构·python·算法·leetcode