C++ solution, using vector as hashmap, O(n)

  • 0
    class Solution {
        bool canConstruct(string ransomNote, string magazine) {
            vector<int> counts(256, 0);
            for (char c : magazine)
            for (char c : ransomNote) {
                if (!counts[c])
                    return false;
            return true;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.