Ransom Note
Problem statement
Given two strings, ransomNote and magazine, return true if the note can be made using letters from the magazine. Otherwise return false.
Each occurrence of a letter in magazine may be used once. Letters may be rearranged, and unused letters are allowed.
Function
canConstruct(ransomNote: String, magazine: String) → booleanExamples
Example 1
ransomNote = "aa"magazine = "ab"return = falseThe note needs two copies of a, but the magazine has only one. Return false.
Example 2
ransomNote = "aa"magazine = "aab"return = trueThe two copies of a make the note. The unused b is allowed. Return true.
Constraints
0 <= ransomNote.length <= 200000 <= magazine.length <= 20000- Both strings contain only lowercase English letters.