Ransom Note
Problem: Ransom Note
Code in Python:
class Solution(object):
def canConstruct(self, ransomNote, magazine):
"""
:type ransomNote: str
:type magazine: str
:rtype: bool
"""
dictionary = {}
for c in magazine:
if c in dictionary: dictionary[c] += 1
else: dictionary[c] = 1
for c in ransomNote:
if c not in dictionary or dictionary[c] == 0:
return False
dictionary[c] -= 1
return True