leetcode 日经贴,python code -repeated-dna-sequences

来源:互联网 发布:gson 源码 编辑:程序博客网 时间:2024/06/15 01:49

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

class Solution:    # @param s, a string    # @return a list of strings    def findRepeatedDnaSequences(self, s):        map2Int = {'A':0, 'C':1, 'G':2, 'T':3}        lst = []        hah = {}        if len(s) <= 10: return lst        current = 0        for i in range(10):            current = current * 4 + map2Int[s[i]]        hah[current] = False        base = 4 ** 9        for i in range(10, len(s)):            current = (current - map2Int[s[i - 10]] * base) * 4 + map2Int[s[i]]            if current not in hah:                hah[current] = False            elif hah[current] == False:                hah[current] = True                lst.append(s[i - 9 : i + 1])        return lst


0 0