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的更多相关文章

  1. [LeetCode] Repeated DNA Sequences 求重复的DNA序列

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  2. LeetCode() Repeated DNA Sequences 看的非常的过瘾!

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  3. [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 ...

  4. LeetCode 187. 重复的DNA序列(Repeated DNA Sequences)

    187. 重复的DNA序列 187. Repeated DNA Sequences 题目描述 All DNA is composed of a series of nucleotides abbrev ...

  5. lc面试准备:Repeated DNA Sequences

    1 题目 All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: &quo ...

  6. Leetcode:Repeated DNA Sequences详细题解

    题目 All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: " ...

  7. 【LeetCode】Repeated DNA Sequences 解题报告

    [题目] All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: &quo ...

  8. [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 ...

  9. 【LeetCode】187. Repeated DNA Sequences 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/repeated ...

随机推荐

  1. C# socket send方法

    转  http://msdn.microsoft.com/zh-cn/library/d318fkch(v=vs.80).aspx

  2. DOM0编程与基础方法

    ## 这里记录一下DOM编程的基础与方法----### DOM 的O:对象 objectO表示Object,对象的意思.JavaScript中对象可以分为三种类型1. 用户定义对象(user-defi ...

  3. Windows无线网“无法连接到这个网络”的解决办法

    最近我的笔记本(Win10系统)连接无线网时总是出现"无法连接到这个网络"的错误.为此折腾了一天,通过各种百度,终于找到了适合我的解决办法,在此记录一下. 问题描述 最近因为宿舍的 ...

  4. Debian8升级4.5内核

    本文讲述如何升级Debian8的内核到4.5版本 0x01:去linux kernel官网https://www.kernel.org/下载4.5的内核,选择tar.xz格式 0x02:想办法把下载好 ...

  5. C#夯实基础之多线程一:初识多线程

    一. 烧水沏茶问题       在小学四年级有一个烧水沏茶问题,可以作为我们今天讨论话题的引子: 客人来了,要烧一壶茶,但是烧水需要5分钟,洗水壶需要1分钟,洗茶杯需要2分钟,接水需要1分钟,找茶叶需 ...

  6. java正则表达式获得html字符串中<img src>的src中的url地址

    /** * 得到网页中图片的地址 */ public static Set<String> getImgStr(String htmlStr) { Set<String> pi ...

  7. appium for iOS config

    appium-doctor: Running iOS Checks ✔ Xcode is installed at /Applications/Xcode.app/Contents/Developer ...

  8. Quartz定时任务简单实例

    文章纲要: 初步搭建一个由Quartz为引擎集群的定时任务模块,功能为每隔30秒打印一条信息(Hello World!!!) 一.环境 Spring MVC Mevan Quartz 2.2.1 二. ...

  9. 转:POI操作Excel导出

    package com.rd.lh.util.excel; import java.beans.PropertyDescriptor; import java.io.FileOutputStream; ...

  10. Linux 安装Mono环境 运行ASP.NET(二)

    一.安装libgdiplus     前面我们已经安装了apr.apr_util.pcre和httpd apache .现在我们来安装libgdiplus Libgdiplus是一个Mono库,用于对 ...