24ms C++ ,vector replace hash table,nice


  • 0
    B

    class Solution {
    public:
    bool canConstruct(string ransomNote, string magazine) {
    vector<int> hash(26,0);
    for(auto c: magazine) hash[c-'a']++;
    for(auto d:ransomNote)
    {
    if(--hash[d-'a']<0) return false;
    }
    return true;
    }
    };


Log in to reply
 

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