C++ Simple Solution


  • 0
    L
    class Solution {
    public:
    bool canConstruct(string ransomNote, string magazine) {
        int m[26] = {0};
        int k[26] = {0};
        for(int i=0;i<magazine.size();i++){
            m[magazine[i]-'a']++;
        }
        for(int i=0;i<ransomNote.size();i++){
            k[ransomNote[i]-'a']++;
        }
        for(int i=0;i<26;i++){
            if(k[i]>m[i])
                return false;
        }
        return true;
    }
    };

Log in to reply
 

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