Short iterative Python solution


  • 0
    V
    class Solution(object):
        def findRepeatedDnaSequences(self, s):
            """
            :type s: str
            :rtype: List[str]
            """
            int_hash = {}
            res = []
            for i in xrange(len(s)-10 +1):
                if s[i:i+10] in int_hash:
                    res.append(s[i:i+10])
                else:
                    int_hash[s[i:i+10]] = 1
            return list(set(res))
    

Log in to reply
 

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