Python one-pass O(n) solution


  • 0
    class Solution(object):
        def findRepeatedDnaSequences(self, s):
            """
            :type s: str
            :rtype: List[str]
            """
            seen = set()
            duplicate = set()
            for i in xrange(10, len(s)+1):
                sequence = s[i-10:i]
                if sequence in seen:
                    duplicate.add(sequence)
                else:
                    seen.add(sequence)
            return list(duplicate)
    

Log in to reply
 

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