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 ...
随机推荐
- 【SpringBoot】数据库操作之整合Mybaties和事务讲解
========================8.数据库操作之整合Mybaties和事务讲解 ================================ 1.SpringBoot2.x持久化数 ...
- Excel函数之vlookup的用法
Vlookup函数用法: 实例: 要将编号对照表中的图书名称根据两表中的图书编码字段引入 订单明细中. Vlookup函数 参数一:键入一个需要搜索的字段,这里需要通过订单明细中的图书编号在编号对照离 ...
- 基础:位(bit)、字节(byte)、字符、编码之间的关系
1.位: 数据存储的最小单位.每个二进制数字0或者1就是1个位: 2.字节: 8个位构成一个字节:即:1 byte (字节)= 8 bit(位): 1 KB = 1024 B(字节): 1 MB = ...
- BottomNavigationView 使用
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.Cons ...
- rpm软件包、yum软件仓库、systemd初始化进程
rpm软件包.yum软件仓库.systemd初始化进程 作者:Eric 微信:loveoracle11g 红帽软件包管理器rpm (Redhat Package Manager) RPM会建立统一的数 ...
- 【亲测】关于HTTP协议~
如果有一点点基本的开发者工具基础知识,我们知道:Elements是用来查看网页结构的,也就是可以看到整体的HTML语言:Console是控制台,Network是请求想相应状态. 1)一个Name就是一 ...
- python使用 openpyxl包 excel读取与写入
'''### 写入操作 ###from openpyxl import Workbook#实例化对象wb=Workbook()#创建表ws1=wb.create_sheet('work',0) #默认 ...
- 经典技术之URL
SpringBoot入门 (十) 发送邮件 图表算法—最短路径 三个好用的并发工具类 跨应用Session共享: https://www.cnblogs.com/websharing/p/849586 ...
- 字符串String的API
字符串的理解 1. 字符串的属性 str.length 2. 字符串的方法 charAt() charCodeAt() indexOf() lastIndexOf() slice() substr ...
- 实战ELK(4)Metricbeat 轻量型指标采集器
一.介绍 用于从系统和服务收集指标.从 CPU 到内存,从 Redis 到 Nginx,Metricbeat 能够以一种轻量型的方式,输送各种系统和服务统计数据. 1.系统级监控,更简洁(轻量型指标采 ...