Python Solution - Substring

  • 1
    class Solution(object):
        def canConstruct(self, ransomNote, magazine):
            :type ransomNote: str
            :type magazine: str
            :rtype: bool
            for ch in ransomNote:
                index = -1
                    index = magazine.index(ch)
                except ValueError:
                    index = -1
                if index == -1:
                    return False
                magazine = magazine[:index] + magazine[index+1:]
            return True

Log in to reply

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