32ms c++ solution


  • 0
    H
    bool canConstruct(string ransomNote, string magazine) {
        int  m[26] ={0};
        for(auto a : magazine )
            m[a-'a']++;
        for(auto a:ransomNote){
            if(m[a-'a'] == 0) return false;
            else    m[a-'a']--;
        }
        return true;
    

    }


Log in to reply
 

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