Python O(n) solution without count()


  • 0
    A
    def canConstruct(self, ransomNote, magazine):
            """
            :type ransomNote: str
            :type magazine: str
            :rtype: bool
            """
            m = list(magazine)
            for i in ransomNote:
                if i in m:
                    m.remove(i)
                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.