美文网首页Leetcode
Leetcode 383. Ransom Note

Leetcode 383. Ransom Note

作者: SnailTyan | 来源:发表于2021-05-06 16:39 被阅读0次

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

Ransom Note

2. Solution

  • Version 1
class Solution:
    def canConstruct(self, ransomNote: str, magazine: str) -> bool:
        ransom = Counter(ransomNote)
        mag = Counter(magazine)
        for k, _ in ransom.items():
            if k in mag:
                if ransom[k] > mag[k]:
                    return False
            else:
                return False
        return True

Reference

  1. https://leetcode.com/problems/ransom-note/

相关文章

网友评论

    本文标题:Leetcode 383. Ransom Note

    本文链接:https://www.haomeiwen.com/subject/nnyddltx.html