187. Repeated DNA Sequences重复的DNA子串序列
[抄题]:
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"]
[暴力解法]:
时间分析:
空间分析:
[优化后]:
时间分析:
空间分析:
[奇葩输出条件]:
- 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
[一句话思路]:
[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):
[画图]:
[一刷]:
- set的判断语句 没加就自己自动加 没必要再写一遍
- 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子串序列的更多相关文章
- 187 Repeated DNA Sequences 重复的DNA序列
所有DNA由一系列缩写为A,C,G和 T 的核苷酸组成,例如:“ACGAATTCCG”.在研究DNA时,识别DNA中的重复序列有时非常有用.编写一个函数来查找DNA分子中所有出现超多一次的10个字母长 ...
- Leetcode187. Repeated DNA Sequences重复的DNA序列
所有 DNA 由一系列缩写为 A,C,G 和 T 的核苷酸组成,例如:"ACGAATTCCG".在研究 DNA 时,识别 DNA 中的重复序列有时会对研究非常有帮助. 编写一个函数 ...
- [leetcode]187. Repeated DNA Sequences寻找DNA中重复出现的子串
很重要的一道题 题型适合在面试的时候考 位操作和哈希表结合 public List<String> findRepeatedDnaSequences(String s) { /* 寻找出现 ...
- [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. 重复的DNA序列(Repeated DNA Sequences)
187. 重复的DNA序列 187. Repeated DNA Sequences 题目描述 All DNA is composed of a series of nucleotides abbrev ...
- 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 ...
- [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] 187. Repeated DNA Sequences 解题思路
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
- [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 ...
随机推荐
- Docker Compose(八)
Docker Compose 是Docker官方编排(Orchstration)项目之一,负责快速在集群中部署分布式应用. Dockerfile可以让用户管理一个单独的应用容器:而Compose则 ...
- fullCalendar使用经验总结
fullCalendar日历控件官方网址: https://fullcalendar.io/ 1.需要引入的文件 <link href="~/assets/fullcalendar-3 ...
- springboot @RequestBody使用JsonSerialize与 JsonDeserialize自定义转参数,处理Date日期格式
JsonDeserialize: 1.请求接收的是一个json,并且由对象接收 @RequestMapping(value = "/query", method = {Reques ...
- jmeter配置脚本录制进行抓包并快速分析、定位接口问题
对于测试人员.开发人员来说,善用抓包工具确实是快速分析和定位问题的一大必备神技,现将配置过程记录如下: 1.打开jmeter后,首先添加一个线程组: 2.线程组可以重新命名按项目名称分类 3.然后在工 ...
- UEFI和GPT下硬盘克隆后的BCD引导修复
UEFI和GPT下硬盘克隆后的BCD引导修复-Storm_Center http://www.stormcn.cn/post/1901.html 当硬盘引导换成GPT,系统启动也变成UEFI后,如果直 ...
- Ubuntu16.04安装Truffle和TestRPC
系统环境 Ubuntu16.04; NodeJS: v6.10.2; NPM: 3.10.10: Truffle: 2.0.8; TestRPC: 3.0.5 安装步骤 注意:以root用户 ...
- redis学习链接收藏
1.redis命令大全--官网 2.redis命令大全--中文翻译版 3.源码(注释版):redis3.0 4.程序代码:<redis入门指南(第二版)>第五章 5.最新的redis-st ...
- 随机森林RandomForest
ID3,C4.5决策树的生成: 输入:训练集D,特征集A,阈值eps, 输出:决策树T 若D中所有样本属于同一类Ck,则T为单节点树,将类Ck作为该结点的类标记,返回T: 若A为空集,即没有特征作为划 ...
- suricata 配置文件threshold
threshold threshold(阈值)关键字可用于控制规则的警报频率,它有3种模式: threshold: type <threshold|limit|both>, track & ...
- VS2017打包设置
本文为网络贴文,引用于:http://www.cnblogs.com/overstep/p/6942423.html 一. 安装打包插件: 安装打包插件:Microsoft Visual Studi ...