GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — algorithms/backtrack/letter_combination.py at master · deba999/algorithms Expand file tree/ Copy pathletter_combination.pyMore file actions 35 lines (30 loc) · 752 Bytes / Copy pathletter_combination.pyFile metadata and controls35 lines (30 loc) · 752 Bytes 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 33 34 35 """ Given a digit string, return all possible letter combinations that the number could represent. Input:Digit string "23" Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]. """ def letter_combinations(digits: "str") -> "List[str]": if digits == "": return [] kmaps = { "2": "abc", "3": "def", "4": "ghi", "5": "jkl", "6": "mno", "7": "pqrs", "8": "tuv", "9": "wxyz" } ans = [""] for num in digits: tmp = [] for an in ans: for char in kmaps[num]: tmp.append(an + char) ans = tmp return ans if __name__ == "__main__": digit_string = "23" print(letter_combinations(digit_string)) |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |