Hash Tables: Ransom Note

#!/bin/python3

import math
import os
import random
import re
import sys

# Complete the checkMagazine function below.

from collections import defaultdict

def checkMagazine(magazine, note):
    zd1= defaultdict(int)
    zd2= defaultdict(int)
    for ele in magazine:
        zd1[ele]+=1
    for ele in note:
        zd2[ele]+=1
    for ele in zd2.items(): ###注意不能少写.items()
        if zd1[ele[0]]< ele[1]:
            print('No')
            return
    print('Yes')

if __name__ == '__main__':
    mn = input().split()

    m = int(mn[0])

    n = int(mn[1])

    magazine = input().rstrip().split()

    note = input().rstrip().split()

    checkMagazine(magazine, note)
发布了163 篇原创文章 · 获赞 90 · 访问量 6280

猜你喜欢

转载自blog.csdn.net/weixin_45405128/article/details/104230472
今日推荐