From ec159367b345cab6e2a8e102f4b9b648c0ebd9b6 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Tue, 10 Jul 2018 10:11:58 +0800 Subject: [PATCH] Create 383.cpp --- LeetCode-CN/383.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 LeetCode-CN/383.cpp diff --git a/LeetCode-CN/383.cpp b/LeetCode-CN/383.cpp new file mode 100644 index 0000000..58d6fd6 --- /dev/null +++ b/LeetCode-CN/383.cpp @@ -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); + } +};