Memory Exceeded error. It shouldn't be possible for dict to grow larger than n


  • 0
    J

    I'm getting memory exceeded error. I don't have any problems when running this on my computer. I even tried handing my dict to the GC before starting the next iteration. What am I missing?

    class Solution:
        # @return an integer
        def lengthOfLongestSubstring(self, s):
            if len(s) == 0:
                return 0
            checker = {}
            sliceIndex = 0
            for i, val in enumerate(s):
                if val not in checker:
                    checker[val] = i
                else:
                    sliceIndex = checker[val]
                    break
            
            count = len(checker)
            checker = None
            nextCount = self.lengthOfLongestSubstring(s[sliceIndex+1:])
            
            if count > nextCount:
                return count
            return nextCount

Log in to reply
 

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