哈希表,记录每 10 位的字符串出现数量,出现次数超过 1 次的加入到结果列表中

#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param DNA string字符串 1
# @return string字符串一维数组
#
from collections import defaultdict
class Solution:
    def repeatedDNA(self , DNA: str) -> List[str]:
        # write code here
        count = defaultdict(int)
        for i in range(len(DNA) - 9):
            count[DNA[i:i + 10]] += 1
        res = []
        for k, v in count.items():
            if v > 1:
                res.append(k)
        return res