Create 383. Ransom Note.md

This commit is contained in:
唐树森 2018-10-08 23:27:54 +08:00 committed by GitHub
parent 1e2bddceec
commit 987597926f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

16
383. Ransom Note.md Normal file
View File

@ -0,0 +1,16 @@
# [383. Ransom Note](https://leetcode.com/problems/ransom-note/description/)
# 思路
用一个大小为26的数组count记录magazine中26个字母的出现次数只要每个字母出现次数不小于ransomNote对应字母次数就行了。
# C++
```
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
vector<int>count(26);
for(char c: magazine) count[c - 'a']++;
for(char c: ransomNote)
if(0 > --count[c - 'a']) return false;
return true;
}
};
```