Python solution - elegant


  • 0
    G
    class Solution(object):
        def canConstruct(self, ransomNote, magazine):
            """
            :type ransomNote: str
            :type magazine: str
            :rtype: bool
            """
            for letter in ransomNote:
                if letter in magazine:
                    nmagazine = magazine.replace(letter, '', 1)
                    magazine = nmagazine
                else:
                    return False
            return True
    

Log in to reply
 

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