当前位置:网站首页>187. repeated DNA sequences
187. repeated DNA sequences
2022-07-01 03:43:00 【Sun_ Sky_ Sea】
187. Repetitive DNA Sequence
Original title link :https://leetcode.cn/problems/repeated-dna-sequences/
DNA Sequence It consists of a series of nucleotides , Abbreviation for ‘A’, ‘C’, ‘G’ and ‘T’..
for example ,“ACGAATTCCG” It's a DNA Sequence .
Research on DNA when , distinguish DNA The repeats in are very useful .
Given a representation DNA Sequence String s , Return all in DNA More than once in a molecule The length is 10 Sequence ( Substring ). You can press In any order Return to the answer .
Example 1:
Input :s = “AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT”
Output :[“AAAAACCCCC”,“CCCCCAAAAA”]
Example 2:
Input :s = “AAAAAAAAAAAAA”
Output :[“AAAAAAAAAA”]
Tips :
0 <= s.length <= 105
s[i]==‘A’、‘C’、‘G’ or ‘T’
Their thinking :
Traversal string s, from s From the beginning of to len(s) - 10 + 1 Index length of , The span is 10, Count the number of occurrences each time , Be equal to 2 The second time is in accordance with the meaning of the question , Greater than 2 If you record it in the answer list again, there will be a repetition , So the judgment condition is equal to 2 Next time .
Code implementation :
class Solution:
def findRepeatedDnaSequences(self, s: str) -> List[str]:
from collections import defaultdict
ans = []
# Use a dictionary to record the number of occurrences of a string
# Use int initialization
freq_dict = defaultdict(int)
# Traverse s, The subscript that can be indexed is from 0 To len(s) - 10 + 1
for i in range(len(s) - 9):
# Every time I go i To i+10 Substring of the span of
sub_s = s[i: i + 10]
# Count the times
freq_dict[sub_s] += 1
# The meaning of the question requires more than once , Then the number of occurrences is greater than or equal to 2 Meet the requirements for the first time
# Greater than 2 Duplicate values will be inserted , Or use set Weight removal can also
if freq_dict[sub_s] == 2:
ans.append(sub_s)
return ans
reference :
https://leetcode.cn/problems/repeated-dna-sequences/solution/zhong-fu-de-dnaxu-lie-by-leetcode-soluti-z8zn/
边栏推荐
- How to use hybrid format to output ISO files? isohybrid:command not found
- How to display scrollbars on the right side of the background system and how to solve the problem of double scrollbars
- 【EI会议】2022年国际土木与海洋工程联合会议(JCCME 2022)
- multiple linear regression
- 165. 比较版本号
- 168. Excel表列名称
- 241. 为运算表达式设计优先级
- bootsrap中的栅格系统
- Golang multi graph generation gif
- The shell script uses two bars to receive external parameters
猜你喜欢

FCN全卷积网络理解及代码实现(来自pytorch官方实现)

【TA-霜狼_may-《百人计划》】2.1 色彩空间

Random seed torch in deep learning manual_ seed(number)、torch. cuda. manual_ seed(number)

Are you still wasting brain cells for self-study? This interview note is definitely the ceiling of station C

Promql select time series

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

【TA-霜狼_may-《百人计划》】1.3纹理的秘密

小程序容器技术与物联网IoT的结合点

完全背包问题

pytorch训练深度学习网络设置cuda指定的GPU可见
随机推荐
Ouc2021 autumn - Software Engineering - end of term (recall version)
Feature Pyramid Networks for Object Detection论文理解
Pyramid scene parsing network [pspnet] thesis reading
pytorch nn. AdaptiveAvgPool2d(1)
241. 为运算表达式设计优先级
实现pow(x,n)函数
完全背包问题
RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs
[party benefits] jsonobject to string, leave blank
Online public network security case nanny level tutorial [reaching out for Party welfare]
Pyramid Scene Parsing Network【PSPNet】论文阅读
Blueprism registration, download and install -rpa Chapter 1
205. 同构字符串
Are you still wasting brain cells for self-study? This interview note is definitely the ceiling of station C
【TA-霜狼_may-《百人计划》】2.1 色彩空间
171. Excel 表列序号
IPv4 and IPv6, LAN and WAN, gateway, public IP and private IP, IP address, subnet mask, network segment, network number, host number, network address, host address, and IP segment / number - what does
[ta - Frost Wolf May - 100 people plan] 2.3 Introduction aux fonctions communes
数据库中COMMENT关键字的使用
10、Scanner. Next() cannot read spaces /indexof -1