leetcode:383. 赎金信(简单,字符串)
作者:互联网
题目:
代码:自己写的,不错
class Solution:
def canConstruct(self, ransomNote: str, magazine: str) -> bool:
c = set(ransomNote)
for c1 in c:
if ransomNote.count(c1)>magazine.count(c1):
return False
return True
1.set,直接提取字符串中的元索去重。
2.字符串的count函数。
标签:ransomNote,count,set,return,383,字符串,赎金,c1,leetcode 来源: https://blog.csdn.net/weixin_42721412/article/details/110296601