leetcode : Letter Combinations of a Phone Number
runtime 0 ms, beats 100% of cpp submissions
O(k^n) solution with explanation
tags: recursion
๐ link
Letter Combinations of a Phone Number
๐ description
็ตฆๅฎไธๅๆ้ต็่ผธๅ ฅๅญไธฒ๏ผๆ่ๅบๆๆๅฏ่ฝ็่กจ็คบๆๆ
2 -> abc 3 -> def 4 -> ghi 5 -> jkl 6 -> mno 7 -> pqrs 8 -> tuv 9 -> wxyz
ex. digits = "23" output = ["ad","ae","af","bd","be","bf","cd","ce","cf"]
๐ง solution
ไธๅ็ถๅ ธ็ๅ จๆๅ้ก็ฎ๏ผๅจๆฏๅ้ๆฎต้ฝๆ็ถๅ index ็ๆๆๅฏ่ฝ่กจ็คบๆนๅผ
โณ time complexity
่ฆๆ่ๆฏๅ index ็ๆๆๅฏ่ฝๅญๅ
๏ผๆฏๅๅญๅ
ๆ 3 ๆ 4 ๅๅฏ่ฝ๏ผๅญไธฒ้ทๅบฆ็บ n ๏ผ ๆ้่ค้ๅบฆ็บ O(k^n)
็ธฝๆ้่ค้ๅบฆ O(k^n)
๐ code
1 | class Solution { |