C simple Solution,6ms, 5lines


  • 0
    W
    bool canConstruct(char* ransomNote, char* magazine) {
        while(*ransomNote++!='\0'){
        	char *tmp=strchr(magazine,*(ransomNote-1));
        	if(!tmp) return false;
        	else *tmp=' ';}
        return true;
    }
    

Log in to reply
 

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