Create 383.cpp

master
Kirigaya Kazuto 2018-07-10 10:11:58 +08:00 committed by GitHub
parent 52f610aeae
commit ec159367b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

9
LeetCode-CN/383.cpp Normal file
View File

@ -0,0 +1,9 @@
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
int bin[26] = { 0 };
for (const auto& c : magazine) ++bin[c - 'a'];
for (const auto& c : ransomNote) --bin[c - 'a'];
return find_if(bin, bin + 26, [](const int& x) {return x < 0; }) == (bin + 26);
}
};