2 lines Python

  • 0

    Here I use a counter called count to store the occurrence of each 10 digits substring. The time complexity is O(n*m) while m is a constant 10 which leads to O(n).

    class Solution(object):
        def findRepeatedDnaSequences(self, s):
            :type s: str
            :rtype: List[str]
            count = collections.Counter(s[i: i+10] for i in range(len(s)-9))
            return [key for key in count if count[key] > 1]

Log in to reply

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