Skip to content

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

Merged
merged 1 commit into from
Oct 29, 2020

Conversation

ztianming
Copy link
Contributor

添加C++、Java、Python语言支持

添加C++、Java、Python语言支持
Copy link
Owner

@azl397985856 azl397985856 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你还精通了 Python 厉害。

不过这道题, 我不想用回溯了, 我想用笛卡尔积去做。

@azl397985856
Copy link
Owner

azl397985856 commented Oct 29, 2020

# 输入:"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)
   

@ztianming
Copy link
Contributor Author

ztianming commented Oct 29, 2020 via email

@azl397985856
Copy link
Owner

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.

你看我上面的代码解法怎么样

@ztianming
Copy link
Contributor Author

ztianming commented Oct 29, 2020 via email

@azl397985856
Copy link
Owner

那有兴趣给我这个解法加多语言么

@azl397985856 azl397985856 changed the title Update 17.Letter-Combinations-of-a-Phone-Number.md feat(ml): $17.Letter-Combinations-of-a-Phone-Number.md Oct 29, 2020
@azl397985856 azl397985856 merged commit 313d08f into azl397985856:master Oct 29, 2020
@ztianming
Copy link
Contributor Author

ztianming commented Oct 29, 2020 via email

azl397985856 pushed a commit that referenced this pull request Aug 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants