Faaez Razeen

Ransom Note

  • 1 min read
  • String
  • LC-Easy

3 years ago

Solution

TimeSpaceExplanation
O(n)O(1)Limited charset, so space complexity is constant.
def canConstruct(self, ransomNote: str, magazine: str) -> bool: mag_count = Counter(magazine) for ch in ransomNote: if ch not in mag_count or mag_count[ch] == 0: return False mag_count[ch] -= 1 return True