Simple C++ solution


  • 1
    C

    class Solution {
    public:
    bool canConstruct(string ransomNote, string magazine) {
    int i;
    int letter1[26] = {0};
    for(i = 0; i < magazine.length(); i++)
    {
    letter1[magazine[i]-'a']++;
    }
    for(i = 0; i < ransomNote.length(); i++)
    {
    letter1[ransomNote[i]-'a']--;
    if(letter1[ransomNote[i]-'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.