C++_Using Vector_Accepted


  • 0

    #code block

        class Solution {
        public:
        bool canConstruct(string ransomNote, string magazine) {
        int n = ransomNote.size(), m = magazine.size();
        vector<int> check(26,0);
    
        for(int i = 0; i < m; i++){
            check[magazine[i] - 'a']++;
        }
        for(int j = 0; j < n; j++){
            if(check[ransomNote[j] - 'a'] <= 0) {return false;}
            else{check[ransomNote[j] - 'a']--;}
        }
        return true;
    }
    

    };


Log in to reply
 

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