C++ Concise Simple Solution


  • 0
    W
    class Solution {
    public:
    	bool canConstruct(string ransomNote, string magazine) {
    		unordered_map<char, int> char_count;
    		for (auto c : magazine) ++char_count[c];
    		for (auto c : ransomNote)
    			if (char_count[c] == 0) return false;
    			else --char_count[c];
    		return true;
    	}
    };
    

Log in to reply
 

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