Pythonic 4-line solution


  • 0
    M
    class Solution(object):
        def findRepeatedDnaSequences(self, s):
            d={}
            for i in range(len(s)-9):
                d[s[i:i+10]]=d.setdefault(s[i:i+10],0)+1
            return [t for t in d if d[t]>1]
    

    This is slow however, beating only 37.31% submission.


Log in to reply
 

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