Leetcode 383 Solution

This article provides solution to leetcode question 383 (ransom-note)

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;
    }
};