28ms c++ solutino


  • 0
    H
    ***first ransomNote and after magazine***
    
    bool canConstruct(string ransomNote, string magazine) {
        int  m[26] ={0};
        for(auto a : ransomNote )
            m[a-'a']++;
        int cnt = ransomNote.size();
        for(auto a:magazine){
            if(m[a-'a'] != 0){
                m[a-'a']--;
                cnt--;
            }
            if(cnt ==0) return true;
        }
        if(cnt ==0) return true;
        else return false;
    

    }
    }


Log in to reply
 

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