Leetcode OJ : Repeated DNA Sequences hash python solution
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
class Solution:
# @param s, a string
# @return a list of strings
def findRepeatedDnaSequences(self, s):
hashset, addedset, retlist = set(), set(), []
for x in range(len(s)):
substr = s[x: x + 10]
if substr in hashset:
if substr not in addedset:
retlist.append(substr)
addedset.add(substr)
else:
hashset.add(substr)
return retlist
Leetcode OJ : Repeated DNA Sequences hash python solution的更多相关文章
- [LeetCode#187]Repeated DNA Sequences
Problem: All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: ...
- [LeetCode] Repeated DNA Sequences hash map
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
- Leetcode:Repeated DNA Sequences详细题解
题目 All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: " ...
- 【LeetCode】Repeated DNA Sequences 解题报告
[题目] All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: &quo ...
- [LeetCode] 187. Repeated DNA Sequences 求重复的DNA序列
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
- leetcode 187. Repeated DNA Sequences 求重复的DNA串 ---------- java
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
- 【leetcode】Repeated DNA Sequences(middle)★
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
- Java for LeetCode 187 Repeated DNA Sequences
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
- [LeetCode] 187. Repeated DNA Sequences 解题思路
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
随机推荐
- Searching in a rotated and sorted array
Given a sorted array that has been rotated serveral times. Write code to find an element in this arr ...
- uva 11143
#include<cstdio> #include<cstring> #include<algorithm> #define maxn 5100 #include& ...
- httpclient 302 重定向
主要是由于页面可能不是通过 request.sendRedirect跳转的,可能通过js location跳转的.所以需要拿跳转后的 地址,重新发送请求...如下所示 if (status == H ...
- JAVA面试题:69道Spring面试题和答案
目录 Spring 概述 依赖注入 Spring beans Spring注解 Spring数据访问 Spring面向切面编程(AOP) Spring MVC Spring 概述 1. 什么是spri ...
- ECNU1101-Dinic
题意:从起点到终点有几条特殊路径. 特殊路径指的是:对于任意两条路径,他们的与起点相连的点是不同的点 && 与终点的相连的点是不同的点. /* 题意:从起点到终点有几条特殊路径. 特殊 ...
- java中dao层和service层的区别是什么?
首先解释面上意思,service是业务层,dao是数据访问层.呵呵,这个问题我曾经也有过,记得以前刚学编程的时候,都是在service里直接调用dao,service里面就new一个dao类对象,调用 ...
- 网上图书商城项目学习笔记-035工具类之JdbcUtils及TxQueryRunner及C3P0配置
事务就是保证多个操作在同一个connection,TxQueryRunner通过JdbcUtils获取连接,而JdbcUtils通过ThreadLocal<Connection>确保了不同 ...
- Nginx的反相代理, 负载均衡
转自 http://freeloda.blog.51cto.com/2033581/1288553 大纲 一.前言 二.环境准备 三.安装与配置Nginx 四.Nginx之反向代理 五.Nginx之负 ...
- 最短路径算法之三——Bellman-Ford算法
Bellman-Ford算法 Dijkstra算法无法判断含负权边的图的最短路. 如果遇到负权,在没有负权回路存在时,即便有负权的边,也可以采用Bellman-Ford算法正确求出最短路径. PS:负 ...
- POJ1328——Radar Installation
Radar Installation Description Assume the coasting is an infinite straight line. Land is in one side ...