-
Notifications
You must be signed in to change notification settings - Fork 2
/
Vanity Phone Numbers.py
32 lines (32 loc) · 1022 Bytes
/
Vanity Phone Numbers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""
Intuition
Here we go through the traditional iterative method of one by one traversing through the string and adding the elements of the dictionary likewise in the new list.
"""
class Solution:
def solve(self, digits):
d = {
"2": "abc",
"3": "def",
"4": "ghi",
"5": "jkl",
"6": "mno",
"7": "pqrs",
"8": "tuv",
"9": "wxyz",
}
ls = list(d.get(digits[0]))
temp = []
for i in range(1, len(digits)):
temp = sorted(ls * len(d.get(digits[i])))
c2 = 0
while c2 != len(temp):
for j in range(len(d.get(digits[i]))):
c1 = 0
while c1 != len(d.get(digits[i])):
if c2 == len(temp):
break
temp[c2] += d.get(digits[i])[c1]
c1 += 1
c2 += 1
ls = temp
return ls