当前位置:网站首页>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/
边栏推荐
- RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs
- Develop industrial Internet with the technical advantages of small programs
- Complete knapsack problem
- Valentine's Day is nothing.
- 318. 最大单词长度乘积
- The preorder traversal of leetcode 144 binary tree and the expansion of leetcode 114 binary tree into a linked list
- IPv4和IPv6、局域网和广域网、网关、公网IP和私有IP、IP地址、子网掩码、网段、网络号、主机号、网络地址、主机地址以及ip段/数字-如192.168.0.1/24是什么意思?
- TEC: Knowledge Graph Embedding with Triple Context
- 【TA-霜狼_may-《百人計劃》】2.3 常用函數介紹
- pytorch中的双线性插值上采样(Bilinear Upsampling)、F.upsample_bilinear
猜你喜欢

Implement pow (x, n) function

Leetcode 31 next spread, leetcode 64 minimum path sum, leetcode 62 different paths, leetcode 78 subset, leetcode 33 search rotation sort array (modify dichotomy)

How to display scrollbars on the right side of the background system and how to solve the problem of double scrollbars

快速筛选打卡时间日期等数据:EXCEL筛选查找某一时间点是否在某一时间段内

Learning notes for introduction to C language multithreaded programming

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

Processing of menu buttons on the left and contents on the right of the background system page, and double scrolling appears on the background system page

实现pow(x,n)函数

Binary tree god level traversal: Morris traversal

Future of NTF and trends in 2022
随机推荐
Bilinear upsampling and f.upsample in pytorch_ bilinear
[party benefits] jsonobject to string, leave blank
10. 正则表达式匹配
实现pow(x,n)函数
Server rendering technology JSP
Sort linked list (merge sort)
4、【WebGIS实战】软件操作篇——数据导入及处理
TEC: Knowledge Graph Embedding with Triple Context
[ta - Frost Wolf May - 100 people plan] 2.3 Introduction aux fonctions communes
访问阿里云存储的图片URL实现在网页直接预览略缩图而不直接下载
数据库DDL(Data Definition Language,数据定义语言)知识点
Feature pyramid networks for object detection
How do I use Google Chrome 11's Upload Folder feature in my own code?
[TA frost wolf _may - "hundred people plan"] 1.4 introduction to PC mobile phone graphics API
Appium automation test foundation -- supplement: c/s architecture and b/s architecture description
torch.histc
整合阿里云短信的问题:无法从静态上下文中引用非静态方法
6. Z 字形变换
8. 字符串转换整数 (atoi)
Test function in pychram