Leetcode 383 Solution
This article provides solution to leetcode question 383 (ransom-note)
Access this page by simply typing in "lcs 383" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/ransom-note
Solution
class Solution {
public:
bool canConstruct(string ransomNote, string magazine) {
map<char, int> m;
for (auto it = magazine.begin(); it != magazine.end(); it++)
m[*it]++;
for (auto it = ransomNote.begin(); it != ransomNote.end(); it++)
if (--m[*it] < 0)
return false;
return true;
}
};