-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
feat(ml): $17.Letter-Combinations-of-a-Phone-Number.md #454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
添加C++、Java、Python语言支持
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你还精通了 Python 厉害。
不过这道题, 我不想用回溯了, 我想用笛卡尔积去做。
# 输入:"23"
# 输出:["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
class Solution:
def letterCombinations(self, digits: str) -> List[str]:
mapper = [" ", " ", "abc", "def", "ghi",
"jkl", "mno", "pqrs", "tuv", "wxyz"]
@lru_cache(None)
def backtrack(digits, start):
if start >= len(digits):
return ['']
ans = []
for i in range(start, len(digits)):
for c in mapper[int(digits[i])]:
for p in backtrack(digits, i + 1):
if start == 0:
if len(c + p) == len(digits):
ans.append(c + p)
else:
ans.append(c + p)
return ans
if not digits:
return []
return backtrack(digits, 0)
|
python会一点基本使用,大佬 可以之后再上笛卡尔积,实现多方法题解
…------------------ 原始邮件 ------------------
发件人: "lucifer"<[email protected]>;
发送时间: 2020年10月29日(星期四) 中午11:41
收件人: "azl397985856/leetcode"<[email protected]>;
抄送: "天明"<[email protected]>; "Author"<[email protected]>;
主题: Re: [azl397985856/leetcode] Update 17.Letter-Combinations-of-a-Phone-Number.md (#454)
@azl397985856 commented on this pull request.
你还精通了 Python 厉害。
不过这道题, 我不想用回溯了, 我想用笛卡尔积去做。
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
你看我上面的代码解法怎么样 |
从命名、边界判断 挺好的,------------------ 原始邮件 ------------------
发件人: "lucifer"<[email protected]>
发送时间: 2020年10月29日(星期四) 中午11:53
收件人: "azl397985856/leetcode"<[email protected]>;
抄送: "Zong"<[email protected]>;"Author"<[email protected]>;
主题: Re: [azl397985856/leetcode] Update 17.Letter-Combinations-of-a-Phone-Number.md (#454)
|
那有兴趣给我这个解法加多语言么 |
我先试试------------------ 原始邮件 ------------------
发件人: "lucifer"<[email protected]>
发送时间: 2020年10月29日(星期四) 下午2:09
收件人: "azl397985856/leetcode"<[email protected]>;
抄送: "Zong"<[email protected]>;"Author"<[email protected]>;
主题: Re: [azl397985856/leetcode] Update 17.Letter-Combinations-of-a-Phone-Number.md (#454)
|
添加C++、Java、Python语言支持