Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Time complexity = (k^n)*n where k=max count of all the chars for each digit ie.4 for 7='pqrs' and n for string building for all the chars.
- '''
- def fun(num,cur,i,ans):
- if i>=len(num) and cur!="":
- ans.append(cur)
- return
- dict={"2":"abc","3":"def","4":"ghi","5":"jkl",'6':"mno","7":"pqrs","8":"tuv","9":"wxyz"}
- current_num=num[i]
- val=dict[current_num]
- print(current_num,cur)
- for k in val:
- fun(num,cur+k,i+1,ans)
- class Solution:
- def letterCombinations(self, num: str) -> List[str]:
- ans=[]
- fun(str(num),"",0,ans)
- return ans
Advertisement
Add Comment
Please, Sign In to add comment