[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 ...
随机推荐
- CentOS光盘挂载命令以及安装软件
最近又学习了一个命令:mount 挂载命令,我们在安装软件的时候,直接敲命令install 包名,但是这里其实是联网安装的, 如果使用光盘,从本地安装就要使用mount命令. 1.我的linux系统是 ...
- EXCEL 2010学习笔记 —— VLOOKUP函数 嵌套 MATCH 函数
match index vlookup 等函数都是查找引用类函数,需要查找的时候关键变量只有两个,区域+位置,区域的选择注意是否需要锁定,位置的确定可以通过输入特定的行号和列号. match() ma ...
- AM335x kernel4.4.12 LCD 时钟翻转设置记录
TI AM335x kernel 4.4.12 LCD display 时钟翻转记录 因为公司硬件上已经确定LCD 转LVDS 转换芯片上确认以上升沿时钟为基准,所以只能在软件上调整相关东西. 入口在 ...
- 架构和模式的区别:三层架构和MVC在应用开发中的位置
架构是系统层面的,可以是多层架构,也可以是事件驱动架构,也可以是微服务架构. 模式是GUI应用的一种职责分离设计. 三层架构(包含多层架构)和 MVC模式(包含MVP, MVVM) 没什么关系,它们不 ...
- h5网页的知识点
http://www.tuicool.com/articles/7BfaymE http://blog.csdn.net/minidrupal/article/details/39611605?utm ...
- js 对数据转换成数据容量单位
function bytesToSize(value) { alert(value); alert('value'); debugger; if (value === 0) return '0 B'; ...
- Python使用TuShare将股票数据保存到Oracle数据
TuShare是个获取股票数据的模块包,我们进行分析,需要将股票数据保存到本地,避免每次都从网上获取,由于本机装有ORCALE,以ORACLE为例介绍如何保存股票数据到本地. 一.大致思路:我们先获取 ...
- sudo:有效用户 ID 不是 0,sudo 属于 root 并设置了 setuid 位吗
遇见这种问题应该检查sudo文件拥有者名称 ---x--x--x. 1 cmp cmp 130720 sudo 明显拥有者有问题 chown root:root /usr/bin/sudo chmo ...
- jquery追加内容
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- 【Java EE 学习 83 上】【SpringMVC】【基本使用方法】
一.SpringMVC框架概述 什么是SpringMVC?SpringMVC是一个和Struts2差不多的东西,他们的作用和性质几乎是相同的,甚至开发效率上也差不多,但是在运行效率上SpringMVC ...