[Leetcode] Repeated DNA Sequences
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"].
大神的代码: http://blog.csdn.net/wzy_1988/article/details/44224749
-----------------------------------------------------------------
Native method:
public class Solution {
public List<String> findRepeatedDnaSequences(String s) {
List<String> res = new ArrayList<>();
if(s == null || s.length() < 2)
return res;
HashMap<String, Integer> hm = new HashMap<>();
for(int i = 0; i < s.length() - 9; ++i) {
String temp = s.substring(i, i + 10);
if(hm.containsKey(temp))
hm.put(temp, hm.get(temp) + 1);
else
hm.put(temp, 1);
}
for(Map.Entry<String, Integer> entry: hm.entrySet()) {
if(entry.getValue() > 1)
res.add(entry.getKey());
}
return res;
}
}
但是这种写法浪费了太多的空间。
---------------------------
Method 2: 利用二进制, 存储整数。
http://segmentfault.com/a/1190000002601702
[Leetcode] Repeated DNA Sequences的更多相关文章
- [LeetCode] Repeated DNA Sequences 求重复的DNA序列
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: "ACG ...
- [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 187. 重复的DNA序列(Repeated DNA Sequences)
187. 重复的DNA序列 187. Repeated DNA Sequences 题目描述 All DNA is composed of a series of nucleotides abbrev ...
- lc面试准备:Repeated DNA Sequences
1 题目 All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: &quo ...
- 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 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/repeated ...
随机推荐
- web自动化工具-liveStyle
web自动化工具-liveStyle LiveStyle. The first bi-directional real-time edit tool for CSS, LESS and SCSS主要用 ...
- [BZOJ3223]Tyvj 1729 文艺平衡树
[BZOJ3223]Tyvj 1729 文艺平衡树 试题描述 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:翻转一个区间,例如原有序序列是5 4 3 2 1,翻转区 ...
- mysql数据库史上最详细起步教程(1)
本文主要讲解mysql的操作,尽量保证步骤的详细与清晰,希望能帮到大家. 1.登录后进行数据库的创建:create database lf(数据库名); (一定要记住分号,mysql在语句的结束符就 ...
- 一对一还是一对多? MVP设计前提
设计MVP之前,先要确定好以下模块之间是一对多还是一对一的关系: View ---> Presenter --> Model --> Interface(URL) 就是一个View只 ...
- 设置html title标题左侧的小图标
网页title旁边的小图片设置,图片要求格式必须是.ico,可以使用在线的转换工具把jpg和png图片转换为ico图片,工具地址:http://www.ico.la/ 在html文件中的<hea ...
- mysql nonInstall 版本的安装与配置
最近用到mysql,发现如果想使用最新版本64 bit mysql 需要独特的配置和使用方式 结合最近的研究总结一下安装过程. 首先下载:http://dev.mysql.com/downloads/ ...
- 中国知网cnki(永久会员账号)
中国知网cnki(永久会员账号)大男孩免费分享 网站简介: (中国知网http://www.cnki.net/)中国知网是国家知识基础设施(National Knowledge Infrastru ...
- java servlet
回顾 1三要素是什么? 入口(login.html) 处理(LoginServlet.java) 出口 (success.jsp) 2如何访问servlet http://IP:port/p ...
- Idea 快捷键
Ctrl+Alt+T 选中代码块加try catch等常用快捷操作.如图: psvm+Tab键 快速创建main方法 pout+Tab键 快速打出System.out.println(); Ctrl+ ...
- 在js中添加新节点
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...