Skip to content
CodeShare
All problems

Ransom Note

Check whether one string can be built from another's letters.

EasyStringsHash map

Given two strings ransomNote and magazine, return true if ransomNote can be built from the letters of magazine, and false otherwise.

Each letter in magazine can be used only once.

Examples

Example 1
Input
ransomNote = "a", magazine = "b"
Output
false
Example 2
Input
ransomNote = "aa", magazine = "ab"
Output
false
Why
The magazine has only one a.
Example 3
Input
ransomNote = "aa", magazine = "aab"
Output
true

Constraints

  • 1 <= ransomNote.length, magazine.length <= 10^5
  • Both strings contain only lowercase English letters.