[抄题]:

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.

Example:

Input: s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT"

Output: ["AAAAACCCCC", "CCCCCAAAAA"]

[暴力解法]:

时间分析:

空间分析:

[优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

  1. set转成arraylist直接放到括号里就行了

[奇葩corner case]:

[思维问题]:

[英文数据结构或算法,为什么不用别的数据结构或算法]:

10个数,从开始算,加到9就可以了。

for (int i = 0; i + 9 < s.length(); i++)

.substring包左不包右,所以必须写十位数。但是inde

String ten = s.substring(i, i + 10);
beginIndex =< str的值 < endIndex

[一句话思路]:

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

  1. set的判断语句 没加就自己自动加 没必要再写一遍
  2. set用add,map用put

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分钟肉眼debug的结果]:

[总结]:

set就是判重,一个不够用可以用两个

[复杂度]:Time complexity: O(n) Space complexity: O(n)

[算法思想:迭代/递归/分治/贪心]:

[关键模板化代码]:

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

[代码风格] :

[是否头一次写此类driver funcion的代码] :

[潜台词] :

class Solution {
public List<String> findRepeatedDnaSequences(String s) {
//ini: two sets
List<String> result = new ArrayList<String>();
Set<String> seen = new HashSet<String>();
Set<String> ten = new HashSet<String>(); //cc
if (s.length() == 0) return result; //for loop: get substring
for (int i = 0; i + 9 < s.length(); i++) {
String str = s.substring(i, i+ 10);
if (!seen.add(str)) ten.add(str);
} //return
return new ArrayList(ten);
}
}

187. Repeated DNA Sequences重复的DNA子串序列的更多相关文章

  1. 187 Repeated DNA Sequences 重复的DNA序列

    所有DNA由一系列缩写为A,C,G和 T 的核苷酸组成,例如:“ACGAATTCCG”.在研究DNA时,识别DNA中的重复序列有时非常有用.编写一个函数来查找DNA分子中所有出现超多一次的10个字母长 ...

  2. Leetcode187. Repeated DNA Sequences重复的DNA序列

    所有 DNA 由一系列缩写为 A,C,G 和 T 的核苷酸组成,例如:"ACGAATTCCG".在研究 DNA 时,识别 DNA 中的重复序列有时会对研究非常有帮助. 编写一个函数 ...

  3. [leetcode]187. Repeated DNA Sequences寻找DNA中重复出现的子串

    很重要的一道题 题型适合在面试的时候考 位操作和哈希表结合 public List<String> findRepeatedDnaSequences(String s) { /* 寻找出现 ...

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

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

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

  6. 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 ...

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

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

  8. [LeetCode] 187. Repeated DNA Sequences 解题思路

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

  9. [Swift]LeetCode187. 重复的DNA序列 | Repeated DNA Sequences

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

随机推荐

  1. Socket基础之-启动异步服务侦听

    Socket网络编程第一篇: 本文主要是以代码为主. .NET技术交流群 199281001 .欢迎加入 1 //负责监听的套接字 private Socket socketServer; //通知一 ...

  2. 由override 和 overload 引发的学习感悟

    工作已三年的我,竟然面试的时候去裸考了.想当然的认为有很多东西会在工作中不知不觉积累下来,现在想想,真是扯淡... 我的三年的工作经验是开发测试的工作,主要负责测试用例的自动化实现,稍深一些的是自动化 ...

  3. ubuntu16.04下docker安装和简单使用

    前提条件 操作系统 docker-ce支持的ubuntu版本: Bionic 18.04 (LTS) Xenial 16.04 (LTS) Trusty 14.04 (LTS) 卸载旧版本docker ...

  4. Python——python读取xml实战,作业6(python programming)

    cd_catalog.xml <?xml version="1.0" encoding="ISO-8859-1"?> <!-- Edited ...

  5. time&datetime

    关于time模块的代码部分 1 #_*_coding:utf-8_*_ 2 __author__ = 'Alex Li' 3 4 import time 5 6 7 # print(time.cloc ...

  6. Scrapy实战篇(二)之爬取链家网成交房源数据(下)

    在上一小节中,我们已经提取到了房源的具体信息,这一节中,我们主要是对提取到的数据进行后续的处理,以及进行相关的设置. 数据处理 我们这里以把数据存储到mongo数据库为例.编写pipelines.py ...

  7. 铁板纹理 Base Shape

    软件:Substance Designer 2017.1.2 最近正在根据官方的教程,学习Metal Rust纹理的制作.这篇文章仅记录Base Shape的制作方法. Base Shape最终渲染效 ...

  8. MOBA英雄AI设计分享

    转自:http://www.gamelook.com.cn/2018/07/333877 文/wataloo 1  设计概要 1.1  设计原则和目的 英雄AI的目的主要有: 1.新手过渡局,让玩家刚 ...

  9. 地图api

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. 搭建Tomcat应用服务器、tomcat虚拟主机及Tomcat多实例部署

    一.环境准备 系统版本:CentOS release 6.6 (Final) x86_64 Tomcat版本:tomcat- JDK版本:jdk-8u25-linux-x64 关闭防火墙 软件包下载地 ...