Easy to understand python solution


  • 0
    A
    def canConstruct(self, ransomNote, magazine):
        """
        :type ransomNote: str
        :type magazine: str
        :rtype: bool
        """
        for element in ransomNote:
            if element not in magazine:
                return False
            else:
                i = magazine.find(element)
                magazine = magazine[:i] + magazine[i+1:]
        return True

Log in to reply
 

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