[LeetCode] Letter Combinations of a Phone Number (Java)

Given a digit string, return all possible letter combinations that the number could represent.

A mapping of digit to letters (just like on the telephone buttons) is given below.

Although the above answer is in lexicographical order, your answer could be in any order you want.


It’s a easy question. But we can do it both in recursive way and iterative way.

In the iterative way, we use the result from the previous digits, and then add new letters to them.


Recursive version

 Iterative version


Assuming the average number of letters on every number is m, and the length of digits string is n, then the complexity is O(mn).