这是少考虑了什么问题吗
查看原帖
这是少考虑了什么问题吗
1348231
Orig1nal楼主2024/5/14 21:00
def greed(x,y):
    dict = {}
    for i in x:
        dict[i]=dict.get(i,0)+1 #{'d': 4, 'a': 3, 'w': 2}

    匹配次数=0

    for z in y:
        if z in x and dict[z] >0:#匹配成功
            匹配次数 +=1
            dict[z] -=1  
        #if dict[z] == 0:
        #    del dict[z]   
        #如果dict[i] =0 即失去匹配次数 可以移除也可以不移除   
    
    return 匹配次数

x=input()
y=input()
print(greed(x,y))
2024/5/14 21:00
加载中...