博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Leetcode OJ : Repeated DNA Sequences hash python solution
阅读量:5228 次
发布时间:2019-06-14

本文共 1016 字,大约阅读时间需要 3 分钟。

Total Accepted: 3790 Total Submissions: 21072

 
 

All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T,

for example: "ACGAATTCCG".

When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.

Write a function to find all the 10-letter-long sequences (substrings)

that occur more than once in a DNA molecule.

For example,

Given s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT", Return: ["AAAAACCCCC", "CCCCCAAAAA"].

 

很水的hashtable

1 class Solution: 2     # @param s, a string 3     # @return a list of strings 4     def findRepeatedDnaSequences(self, s): 5         hashset, addedset, retlist = set(), set(), [] 6         for x in range(len(s)): 7             substr = s[x: x + 10] 8             if substr in hashset: 9                 if substr not in addedset:10                     retlist.append(substr)11                     addedset.add(substr)12             else:13                 hashset.add(substr)14         return retlist

 

转载于:https://www.cnblogs.com/ydlme/p/4296060.html

你可能感兴趣的文章
Leetcode 226: Invert Binary Tree
查看>>
http站点转https站点教程
查看>>
解决miner.start() 返回null
查看>>
bzoj 2007: [Noi2010]海拔【最小割+dijskstra】
查看>>
BZOJ 1001--[BeiJing2006]狼抓兔子(最短路&对偶图)
查看>>
C# Dynamic通用反序列化Json类型并遍历属性比较
查看>>
128 Longest Consecutive Sequence 一个无序整数数组中找到最长连续序列
查看>>
定制jackson的自定义序列化(null值的处理)
查看>>
auth模块
查看>>
javascript keycode大全
查看>>
前台freemark获取后台的值
查看>>
log4j.properties的作用
查看>>
游戏偶感
查看>>
Leetcode: Unique Binary Search Trees II
查看>>
C++ FFLIB 之FFDB: 使用 Mysql&Sqlite 实现CRUD
查看>>
Spring-hibernate整合
查看>>
c++ map
查看>>
exit和return的区别
查看>>
发布一个JavaScript工具类库jutil,欢迎使用,欢迎补充,欢迎挑错!
查看>>
discuz 常用脚本格式化数据
查看>>