【LeetCode】【字符串】题号:383. 赎金信

every blog every motto: You will never know unless you try

0. 前言

生活好难,再坚持坚持!

1. 字符串

在这里插入图片描述

1.1 题目

在这里插入图片描述

1.2

class Solution:
    def canConstruct(self, ransomNote: str, magazine: str) -> bool:

        ran_freq = collections.Counter(ransomNote)
        mag_freq = collections.Counter(magazine)

        for ele in ransomNote:

            if ran_freq[ele] > mag_freq[ele]:

                return False
        
        return True

1.3

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_39190382/article/details/119303441