Clean C++ (22ms to 38ms... not very linear in their time scoring...)


  • 0
    F
    class Solution {
    public:
        bool canConstruct(string ransomNote, string magazine) {
            int magHash[256] = {0};
            for(auto ch : magazine) magHash[ch]++;
            for(auto ch : ransomNote){
                magHash[ch]--;
                if(magHash[ch] < 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.