当前位置:网站首页>【LeetCode】Day112-重复的DNA序列
【LeetCode】Day112-重复的DNA序列
2022-08-11 02:51:00 【倒过来是圈圈】
题目
题解
哈希表
哈希表记录长度为10的子串的对应出现次数,也用到了滑动窗口的思想
class Solution {
public List<String> findRepeatedDnaSequences(String s) {
List<String>res=new ArrayList<>();
Map<String,Integer>map=new HashMap<>();
for(int i=0;i<=s.length()-10;i++){
String str=s.substring(i,i+10);//截子串
map.put(str,map.getOrDefault(str,0)+1);
if(map.get(str)==2)
res.add(str);
}
return res;
}
}
时间复杂度: O ( n L ) O(nL) O(nL),L=10 即目标子串的长度,因为substring复杂度是O(L)
空间复杂度: O ( n L ) O(nL) O(nL)
边栏推荐
猜你喜欢

MySQL - an SQL in MySQL is how to be performed?

ROS源代码阅读(1)

入职数字ic设计后的一些工作心得

DOM树的遍历-----修改样式,选择元素,创建和删除节点

A Practical Arrangement of Map GIS Development Matters (Part 1)

The practice of alibaba data synchronization component canal

BUU brushing record

【idea 报错】 无效的目标发行版:17 的解决参考

①In-depth analysis of CAS SSO single sign-on framework source code

ES6 advanced string processing new features
随机推荐
Entity to Vo conversion
BUU brushing record
"How to kick a bad habit to read notes?
Add user error useradd: cannot open /etc/passwd
如何解决高度塌陷
网络安全笔记第四天day4(kali基本操作)
经典面试题 之 GC垃圾收集器
GBJ3510-ASEMI家电电源用整流桥GBJ3510
入职数字ic设计后的一些工作心得
redis学习五redis的持久化RDB,fork,copyonwrite,AOF,RDB&AOF混合使用
①In-depth analysis of CAS SSO single sign-on framework source code
关于地图GIS开发事项的一次实践整理(上)
[idea error] Invalid target distribution: 17 solution reference
js中的this问题
What does the sanction of the mixer Tornado mean for the DeFi market?
CSAPP Data Lab
IDE compilation error: Dangling metacharacter
OpenCV founder: Open source must not be completely free!
重庆纸质发票再见!开住宿费电子发票即将全面取代酒店餐饮加油站发票
comp3331-9331-22t1-midterm复习辅导-tutorial week 5