Letter Combinations of a Phone Number - Leetcode 17

preview_player
Показать описание
Letter Combinations of a Phone Number - Leetcode 17
Рекомендации по теме
Комментарии
Автор

Ouch! Learn Data strucutres and algorithms for FREE at AlgoMap.io!

GregHogg
Автор

Why use dfs when you can just loop through all the options with a nested for?
Correct me if I'm wrong but both should be O(n²) in our case

darknight
Автор

Thank you so much. Keep up the good work

devprakash
Автор

great intro! thank you for showing the code at the end!

ZackWhitbord
Автор

It's a kind of question that anyone can solve given enough time and debugging tools, it would take about 30mins - 1hour, idk if that's too long or anything

vafasadrif
Автор

Why don't you just make two nested loops. For example, if you have 25, then your loop will iterate through each option like this

[a]bc-[j]kl => aj
[a]bc-j[k]l => ak
[a]bc-jk[l] => al
a[b]c-[j]kl => bj
a[b]c-j[k]l => bk
a[b]c-jk[l] => bl
ab[c]-[j]kl => cj
ab[c]-j[k]l => ck
ab[c]-jk[l] => cl

This method is simpler and does not use any additional memory with those tree data structures. Also it could be beneficial for low level languages because if you want to return an array, you know how many elements you can allocate len("abc") * len("jkl") in this case

СергейДехтярёв-ън
Автор

Ohh man that's to simple just import product from itertools module and keep that dict that you named as "letter_map" and then "return product(*[letter_map(digit) for digit in digits])"

Raj.MathsKaDar
Автор

Cool but is better to give better vatiable names like; letter in letters_map
instead of num in letters_map

_a_
Автор

If you use the diggit 23 on this Phone you only can get a ad.
For everything else you need more Button pushes.

germanlmpackt