python leetcode 187. Repeated DNA Sequences

字典查找,注意10-letter-long sequences (substrings)大大降低了难度

class Solution(object):
    def findRepeatedDnaSequences(self, s):
        """
        :type s: str
        :rtype: List[str]
        """
        ls=len(s)
        if ls<=10:
            return []
        mydict={}
        res=[]
        for i in range(ls-9):
            if s[i:i+10] in mydict:
                if mydict[s[i:i+10]]==1:
                    res.append(s[i:i+10])
                mydict[s[i:i+10]]+=1
            else:
                mydict[s[i:i+10]]=1
        return res

你可能感兴趣的:(leetcode,python)