python - repeated dna seq


  • 0
    S
    class Solution(object):
        def findRepeatedDnaSequences(self, s):
            """
            :type s: str
            :rtype: List[str]
            """        
            ans, h = [], {}
            for i in range(len(s)-10+1):
                seq = s[i:i+10]
                if seq in h:
                    if h[seq] == 1:
                        ans.append(seq)
                    h[seq] += 1
                else:
                    h[seq] = 1
            
            return ans
                
    

Log in to reply
 

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