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. Collection小结

    Collection:

  2. nginx负载SignalR

    前几天写了篇聊天室服务器扩展随想,今天有空开始实施第一步, 聊天服务器用SignalR self-host,负载用nginx,当然这只是测试,实际使用可能还需要修改. 第一步,搭好SignalR服务, ...

  3. Mybatis 总结

    1.如何传递多个参数 mybatis中,如果接口有多个参数,那么在mapper.xml中,可以通过#{0,VARCHAR},#{1,VARCHAR}或#{param1,VARCHAR},#{param ...

  4. 如何将 NavigationBar 的半透明效果关闭?

    如何将 NavigationBar 的半透明效果关闭?只需三行代码就可以:self.navigationController.navigationBar.barTintColor = [UIColor ...

  5. MVC -- 后台RedirectToAction传递实体类与字符串

    1.MVC -- 后台RedirectToAction传递实体类 RedirectToAction(控制器,控制器方法,实体类) 2.MVC -- 后台RedirectToAction传递字符串 Re ...

  6. SpringMVC学习

    1,对SpringMVC的理解 a,基于MVC的设计理念 b,采用松散耦合可插拔组件结构,比其他MVC框架更具扩展性和灵活性 c,支持REST风格的URL请求 d,该框架围绕DispatcherSer ...

  7. linux 下查看cpu位数 内核等参数命令(转)

    # uname -a Linux euis1 2.6.9-55.ELsmp #1 SMP Fri Apr 20 17:03:35 EDT 2007 i686 i686 i386 GNU/Linux ( ...

  8. 《Python数据分析》环境搭建之安装Jupyter工具(一)

    (免责声明:本文档是针对Python有经验的用户,如果您对Python了解很少,或者从未使用,建议官方教程用Anaconda安装) 前期准备:Python环境 虽然Jupyter可以运行多种编程语言, ...

  9. python访问MS SqlServer(通过pyodbc)

    #!/usr/bin/env python # -*- coding: utf-8 -*- import pyodbc class MSSQL: """ 封装pyodbc ...

  10. 第三十三篇:使用uiresImporter生成uires.idx及skin.xml

    在SOUI中,使用uires.idx这个文件来记录程序中使用的所有资源文件. 此外绘制对象(ISkinObj)则一般放在skin.xml中描述. 要向一个界面中增加一个新的图片,在没有uiresImp ...