5 lines in Python, 63ms

  • 0

    Note: The time 63ms can be changed according to your submit time, I think it's affected by the server status or server load.

    class Solution(object):
        def canConstruct(self, ransomNote, magazine):
            :type ransomNote: str
            :type magazine: str
            :rtype: bool
            key: Each letter in the magazine string can only be used once in your ransom note.
            ransom_counter = {i: ransomNote.count(i) for i in ''.join(set(ransomNote))}
            for k,v in ransom_counter.items():
                if magazine.count(k) < v:
                    return False
            return True

Log in to reply

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