Ransom Note
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
.
Example 1:
1 | Input: ransomNote = "a", magazine = "b" |
Example 2:
1 | Input: ransomNote = "aa", magazine = "ab" |
Example 3:
1 | Input: ransomNote = "aa", magazine = "aab" |
时间复杂度:O(m+n)
空间复杂度:O(S),S为字符集大小
1 | class Solution { |