187. Repeated DNA Sequences

这一题的看到的比较简单的python解法就是,将10个一组的字符用哈希表记起来,然后判断哈希表的值,代码如下:

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

你可能感兴趣的:(187. Repeated DNA Sequences)