Rolling Hash with Python in O(n) space O(n)


  • -1
    class Solution(object):
        def findRepeatedDnaSequences(self, s):
            """
            :type s: str
            :rtype: List[str]
            """
            dir={}
            res=[]
            for i in range(0,len(s)-9):
                window=s[i:10+i]
                # print window
                if window not in dir:
                    dir[window]=1
                else:
                    dir[window]+=1
                    if dir[window]==2:
                        res.append(window)
                        
            return res
    

  • 0
    L

    lol that's not O(n) space


Log in to reply
 

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