leetcode刷题250天(11)——面试题 16.20. T9键盘

class Solution:
    def getValidT9Words(self, num, words):
    	# 从数字序列推字符序列的组合是1->N
		# 但是从每个字符的数字是一定的
		# 将字符映射为数字 然后看是否来自当前数字组合即可
        res = []

        Reflect = {
            "a":"2","b":"2","c":"2","d":"3","e":"3","f":"3","g":"4",
            "h":"4","i":"4","j":"5","k":"5","l":"5","m":"6","n":"6",
            "o":"6","p":"7","q":"7",        "r":"7","s":"7","t":"8",
            "u":"8","v":"8","w":"9",        "x":"9","y":"9","z":"9",
        }

        for word in words:

            numList = []
            for char in word:
                numList.append(Reflect[char])
                
            reconstruction = "".join(numList)

            if reconstruction == num:
                res.append(word)
        
        return res

作者:dustw1nd
链接:https://leetcode-cn.com/problems/t9-lcci/solution/shu-zi-zi-fu-chuan-1-n-zi-fu-chuan-shu-z-yj02/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值