Leetcode 383. Ransom Note

2021-05-18 16:19:43 浏览数 (1)

1. Description

2. Solution

  • Version 1
代码语言:javascript复制
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/

0 人点赞