Ransom Note

Easy~10 min

Given two strings ransomNote and magazine, return true if ransomNote can be constructed by using the letters from magazine, and false otherwise.

Each letter in magazine can only be used once in ransomNote.

Examples

Example 1
Input: ransomNote = "a", magazine = "b"
Output: false
Explanation: The magazine contains "b" but we need "a". Cannot construct the ransom note.
Example 2
Input: ransomNote = "aa", magazine = "ab"
Output: false
Explanation: We need two "a"s but the magazine only has one "a".
Example 3
Input: ransomNote = "aa", magazine = "aab"
Output: true
Explanation: The magazine has two "a"s, which is enough to construct "aa".

Constraints

  • 1 <= ransomNote.length, magazine.length <= 10^5
  • ransomNote and magazine consist of lowercase English letters
Code
Ctrl+EnterRun|Ctrl+⇧+EnterSubmit
Output

Run your code to see results

Use Cmd+Enter to run