Leetcode

Leetcode 383. Ransom Note

2021-05-06  本文已影响0人  SnailTyan

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

1. Description

Ransom Note

2. Solution

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/
上一篇 下一篇

猜你喜欢

热点阅读