1-liner in Python


  • 0
    O
    class Solution(object):
        def findRepeatedDnaSequences(self, s):
            return [k for k,v in collections.Counter(s[i:i+10] for i in range(len(s))).iteritems() if v>1]
    

    Or if you want to do a little less work:

    class Solution(object):
        def findRepeatedDnaSequences(self, s):
            return [k for k,v in collections.Counter(s[i:i+10] for i in range(len(s)-9)).iteritems() if v>1]
    

Log in to reply
 

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