Easy c


  • 0
    P
    int table[26];
    bool canConstruct(char* ransomNote, char* magazine) {
        int i;
        for(i = 0; i < 26; i++) table[i] = 0;
        while(*magazine)    {table[*magazine - 'a']++; magazine++;}
        while(*ransomNote)  {table[*ransomNote - 'a']--; ransomNote++;}
        for(i = 0; i < 26; i++) if(table[i] < 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.