Skip to content

Commit

Permalink
Create ransom-notes.py
Browse files Browse the repository at this point in the history
  • Loading branch information
gabedonnan authored Jan 27, 2023
1 parent 697f7d5 commit e7615b8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ransom-notes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution:
def canConstruct(self, ransomNote: str, magazine: str) -> bool:
final = defaultdict(int)

if len(ransomNote) > len(magazine):
return False
for letter in ransomNote:
final[letter] -= 1
for letter in magazine:
final[letter] += 1
for letter in final:
if final[letter] < 0:
return False
return True

0 comments on commit e7615b8

Please sign in to comment.