mirror of
https://github.com/arkorty/LeetCode.git
synced 2026-03-17 16:51:46 +00:00
Initial commit
This commit is contained in:
21
Easy/ransom-note/solution.cpp
Normal file
21
Easy/ransom-note/solution.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
bool canConstruct(std::string ransomNote, std::string magazine) {
|
||||
std::unordered_map<char, int> hmap[2];
|
||||
|
||||
for (int i = 0; i < magazine.size(); ++i) {
|
||||
++hmap[0][magazine[i]];
|
||||
}
|
||||
|
||||
for (int i = 0; i < ransomNote.size(); ++i) {
|
||||
if (hmap[0][ransomNote[i]] < ++hmap[1][ransomNote[i]]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user