My O(n) solution based on map in python language


  • 0
    C
    class Solution:
    # @param s, a string
    # @return a list of strings
    def findRepeatedDnaSequences(self, s):
        li = list(s)
        length = len(s)
        i = 0
        dict = {}
        while i + 10 <= length:
            key = s[i: i + 10]
            if key in dict: dict[key] += 1
            else : dict[key] = 1
            i = i + 1
        li = [key for key, value in dict.items() if value > 1]
        return li

Log in to reply
 

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