Simple python solution with str.replace


  • 0
    K

    92% of solutions beaten

    class Solution(object):
        def canConstruct(self, ransomNote, magazine):
            for char in ransomNote:
                if char in magazine:
                    magazine = magazine.replace(char, "", 1)
                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.