Ransom Note
Easy · hash map
You want to put together a message by cutting single letters out of a magazine and pasting them on a page.
Given two strings, note (the message you want) and magazine (the letters you have), return true if the message can be built, and false otherwise.
Every letter of magazine can be cut out at most once, and the order of the letters in the magazine does not matter. The same letter may be needed several times: a note with three "a" needs three separate "a" in the magazine.
Examples
Example 1
Input: note = "pad", magazine = "paddock"
Output: true
The magazine has a "p", an "a" and a "d" to spare.
Example 2
Input: note = "noon", magazine = "nonce"
Output: false
The note needs two "o", but the magazine has only one.
Example 3
Input: note = "tea", magazine = "ate"
Output: true
Order does not matter, only which letters are available.
Constraints
- 1 <= len(note), len(magazine) <= 10^5
- note and magazine contain only lowercase English letters.