8/01/2020

[LeetCode] 187. Repeat DNA Sequences

Problem : https://leetcode.com/problems/repeated-dna-sequences/

Find all 10-letter-long sequences and save into hash table.
Return sequences which's counter > 1.

class Solution:
    def findRepeatedDnaSequences(self, s: str) -> List[str]:
        seen = defaultdict(int)
        
        for i in range(len(s) - 10 + 1):
            seen[s[i:i+10]] += 1
        
        return filter(lambda k: seen[k] > 1, seen.keys())

No comments:

Post a Comment