[抄题]:

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. oracle-pl/sql之三

    集合与记录 set serveroutput on create or replace package my_types authid definer is type my_rec is record ...

  2. py-day3-5 python 函数式编程

    # 函数式(方程式 y = 2*x+1) def calc(x): return 2*x+1 print('得出的结果:',calc(6)) 得出的结果: 13 # 面向过程 def calc(x): ...

  3. Delphi操作剪贴板

    Windows使用剪贴板观察器和观察链.剪贴板观察器是一个显示剪贴板当前内容的窗口.            通常它应该至少能显示三种普通格式的内容:文字CF_TEXT.位图CF_BITMAP.元文件C ...

  4. SQLSERVER创建该存储过程时不会出错,但是执行存储过程时报错

    创建该存储过程时,不会出错,但是执行存储过程时,会报出下面这样的错误 这是因为在存储过程创建时,它先做语法检查,如果通过了语法检查,它会尝试解析它包含的对象名,如果存在也会解析该对象引用的对象是否存在 ...

  5. springboot整合mybatis之注解方式

    1. 创建maven项目,工程目录如下图 2. 在pom.xml文件中添加mybatis依赖. 3. 创建实体类,并生成construct方法,getter和setter方法.同时在数据库中创建对应的 ...

  6. WebService上传下载图片

    WebService服务端 接受要上传的图片 public string UploadImg(byte[] fileBytes, int id) { try { string filePath = M ...

  7. win10安装git

    Git官网下载:https://git-scm.com/download 选择win系统,下载.然后选择安装路径,一路next.安装成功后 打开cmd 输入 git --version 配置信息 设置 ...

  8. numpy学习笔记(三)

    (1)numpy的位操作 序号         操作及描述 1.      bitwise_and 对数组元素执行位与操作 2.      bitwise_or 对数组元素执行位或操作 3.      ...

  9. Linux的命令技巧

    一.使用apt-get installl 方法安装的库或者程序一般的路径如下 1.下载的软件存放位置       /var/cache/apt/archives 2.安装后软件默认位置    /usr ...

  10. react学习笔记(二)

    在以类继承的方式定义的组件中,为了能方便地调用当前组件的其他成员方法或属性(如:this.state),通常需要将事件处理函数运行时的 this 指向当前组件实例. 绑定事件处理函数this的几种方法 ...