Elegant (but slow) python solution


  • 0
    X
    from collections import Counter 
    
    def find_ngrams(input_list, n):
      return zip(*[input_list[i:] for i in range(n)])
    
    class Solution(object):
        def findRepeatedDnaSequences(self, s):
            tengrams = find_ngrams(s, 10)
            c = Counter(tengrams)
            return map(lambda tup: ''.join(tup),filter(lambda seq:c[seq]>1, c.keys()))
    
    
    

Log in to reply
 

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