当前位置:网站首页>187. 重复的DNA序列
187. 重复的DNA序列
2022-07-01 03:23:00 【Sun_Sky_Sea】
187. 重复的DNA序列
原始题目链接:https://leetcode.cn/problems/repeated-dna-sequences/
DNA序列 由一系列核苷酸组成,缩写为 ‘A’, ‘C’, ‘G’ 和 ‘T’.。
例如,“ACGAATTCCG” 是一个 DNA序列 。
在研究 DNA 时,识别 DNA 中的重复序列非常有用。
给定一个表示 DNA序列 的字符串 s ,返回所有在 DNA 分子中出现不止一次的 长度为 10 的序列(子字符串)。你可以按 任意顺序 返回答案。
示例 1:
输入:s = “AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT”
输出:[“AAAAACCCCC”,“CCCCCAAAAA”]
示例 2:
输入:s = “AAAAAAAAAAAAA”
输出:[“AAAAAAAAAA”]
提示:
0 <= s.length <= 105
s[i]==‘A’、‘C’、‘G’ or ‘T’
解题思路:
遍历字符串s,从s的开头到len(s) - 10 + 1的索引长度,跨度是10,每次统计出现的次数,当等于2次的时候符合题意,大于2次的话再记录到答案列表中会出现重复,所以判断条件等于2次即可。
代码实现:
class Solution:
def findRepeatedDnaSequences(self, s: str) -> List[str]:
from collections import defaultdict
ans = []
# 用一个字典记录字符串出现的次数
# 使用int初始化
freq_dict = defaultdict(int)
# 遍历s,能索引的下标是从0到len(s) - 10 + 1
for i in range(len(s) - 9):
# 每次去i到i+10的跨度的子字符串
sub_s = s[i: i + 10]
# 统计次数
freq_dict[sub_s] += 1
# 题意要求不止一次,那么出现次数大于等于2次满足要求
# 大于2会插入重复值,或者使用set去重也可以
if freq_dict[sub_s] == 2:
ans.append(sub_s)
return ans
参考文献:
https://leetcode.cn/problems/repeated-dna-sequences/solution/zhong-fu-de-dnaxu-lie-by-leetcode-soluti-z8zn/
边栏推荐
- 监听器 Listener
- The shell script uses two bars to receive external parameters
- Use of comment keyword in database
- multiple linear regression
- GCC usage, makefile summary
- pytorch中的双线性插值上采样(Bilinear Upsampling)、F.upsample_bilinear
- 详解Spark运行模式(local+standalone+yarn)
- 过滤器 Filter
- Nacos
- E15 solution for cx5120 controlling Huichuan is620n servo error
猜你喜欢

Appium自动化测试基础--补充:C/S架构和B/S架构说明

Take you through a circuit board, from design to production (dry goods)
![Online public network security case nanny level tutorial [reaching out for Party welfare]](/img/66/d9c848a7888e547b7cb28d84aabc24.png)
Online public network security case nanny level tutorial [reaching out for Party welfare]

Research on target recognition and tracking based on 3D laser point cloud

TEC: Knowledge Graph Embedding with Triple Context

LeetCode 144二叉树的前序遍历、LeetCode 114二叉树展开为链表

IPv4和IPv6、局域网和广域网、网关、公网IP和私有IP、IP地址、子网掩码、网段、网络号、主机号、网络地址、主机地址以及ip段/数字-如192.168.0.1/24是什么意思?

LeetCode 31下一个排列、LeetCode 64最小路径和、LeetCode 62不同路径、LeetCode 78子集、LeetCode 33搜索旋转排序数组(修改二分法)

Depth first traversal of C implementation Diagram -- non recursive code

访问阿里云存储的图片URL实现在网页直接预览略缩图而不直接下载
随机推荐
Explain spark operation mode in detail (local+standalone+yarn)
Use of comment keyword in database
Leetcode:剑指 Offer 59 - I. 滑动窗口的最大值
Ultimate dolls 2.0 | encapsulation of cloud native delivery
FCN全卷积网络理解及代码实现(来自pytorch官方实现)
idea插件备份表
[深度学习]激活函数(Sigmoid等)、前向传播、反向传播和梯度优化;optimizer.zero_grad(), loss.backward(), optimizer.step()的作用及原理
Golang multi graph generation gif
网页不能右键 F12 查看源代码解决方案
ECMAScript 6.0
You cannot right-click F12 to view the source code solution on the web page
C语言的sem_t变量类型
[deep learning] activation function (sigmoid, etc.), forward propagation, back propagation and gradient optimization; optimizer. zero_ grad(), loss. backward(), optimizer. Function and principle of st
RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs
使用selenium自动化测试工具爬取高考相关院校专业招生分数线及排名情况
Edge drawing: a combined real-time edge and segment detector
How to display scrollbars on the right side of the background system and how to solve the problem of double scrollbars
串口接收数据方案设计
Gorilla/mux framework (RK boot): RPC error code design
Pyramid scene parsing network [pspnet] thesis reading