Leetcode 17. Letter Combinations of a Phone Number(python)
生活随笔
收集整理的這篇文章主要介紹了
Leetcode 17. Letter Combinations of a Phone Number(python)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
笨方法回溯啦
class Solution(object):def letterCombinations(self, digits):""":type digits: str:rtype: List[str]"""p_map=[" ","*","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"]solution=[]res=""if len(digits)==0: return []self.back_track(res,0,digits,p_map,solution)return solutiondef back_track(self,res,k,digits,p_map,solution):if k==len(digits):solution.append(res)returnfor i in range(len(p_map[int(digits[k])])):res+=p_map[int(digits[k])][i]#print res+"1",solution,k,len(digits)self.back_track(res,k+1,digits,p_map,solution)res=res[:-1]
轉載于:https://www.cnblogs.com/colorss/p/5358339.html
總結
以上是生活随笔為你收集整理的Leetcode 17. Letter Combinations of a Phone Number(python)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 封装各种生成唯一性ID算法的工具类
- 下一篇: 如何用烤面包片?