383. Ransom Note
Question
Given two strings
ransomNote
andmagazine
, returntrue
* ifransomNote
can be constructed by using the letters frommagazine
andfalse
otherwise*.Each letter in
magazine
can only be used once inransomNote
.
Solution
数组统计,统计magazine内的字符。
遍历ransomNote,如果对字符数组位置为0则返回false。
每次遍历减少数组统计结果。
最后返回true。
Code
1 | class Solution { |
383. Ransom Note