C solution 6ms


  • 0
    bool canConstruct(char* ransomNote, char* magazine) {
        int letterCount[128] = {0};
        int index = 0;
        char tmp;
        while((tmp=magazine[index])!=0){
            letterCount[tmp] ++ ;
            index ++;
        }
        index = 0;
        while((tmp=ransomNote[index])!=0){
            letterCount[tmp] -- ;
            if(letterCount[tmp]<0) return false;
            index ++;
        }
        return true;
    }
    

Log in to reply
 

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