Grind 75 Python 做題記錄 383. Ransom Note
Grind 75 Python 做題記錄 383. Ransom Note
答題
class Solution:
def canConstruct(self, ransomNote: str, magazine: str) -> bool:
# 將重複字串過濾,變成一個不重複list
r_list = list(set(ransomNote))
# 遍歷 List
for i in r_list:
# 檢查每個字字數,ransomNote 中某字數不可大於 magazine
if ransomNote.count(i) > magazine.count(i): return False
return True