Python solution with counter


  • 0
    from collections import Counter
    
    class Solution(object):
        def canConstruct(self, ransomNote, magazine):
            c1 = Counter(magazine)
            c2 = Counter(ransomNote)
            return all((c2[k] <= c1.get(k, 0)) for k in c2.iterkeys())
    

Log in to reply
 

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