原题

原题链接

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.

For example,

Given s = “AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT”,

Return:
[“AAAAACCCCC”, “CCCCCAAAAA”].


分析

重复出现的子串,长度为10。
用一个hash来保存,最后结果去重即可。

class Solution{ public:vector<string> findRepeatedDnaSequences(string s){ vector<string>result;unordered_set<string>visited;for(int i=0;i+10<=s.size();++i){string tmp(s.begin()+i,s.begin()+i+10);if(visited.end()==visited.find(tmp)){visited.insert(tmp);}elseresult.push_back(tmp);}//去重result.erase(unique(result.begin(),result.end()),result.end());//打印// ostream_iterator<string> out_it(cout,"\n");// copy(result.begin(),result.end(),out_it);return result;}
};

LeetCode187—Repeated DNA Sequences相关推荐

  1. 187. Repeated DNA Sequences重复的DNA子串序列

    [抄题]: All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: &qu ...

  2. Repeated DNA Sequences @leetcode

    早上到公司第一件事变成了刷leetcode,发现各种题目的各种解法,真心是个挺有趣的过程.比如今天早上碰到的这个DNA序列的问题,一开始完全没有头绪,但是后来看了些文章发现,真的是二进制大法好啊! 会 ...

  3. 【Lintcode】1335. Repeated DNA Sequences

    题目地址: https://www.lintcode.com/problem/1335 给定一个只含 A , C , G , T A,C,G,T A,C,G,T的字符串 s s s,求其所有出现了多次 ...

  4. Leetcode187-Repeated DNA Sequences

    题目描述 所有DNA序列都可以用 A,C,G,T 四个字母表示,比如 "ACGAATTCCG",研究DNA序列时,有时识别重复子串是很有意义的. 请编写一个程序,找到所有长度为10 ...

  5. bwt比对算法 C语言,DNA比对算法:BWT

    DNA比对算法:BWT BWT算法,实质上是前缀树的一种实现.那么什么是前缀树呢? 一.前缀树 对于问题p in S?如果S=rpq,那么p为S前缀rp的一个后缀. 于是,为了判断p in S 是否成 ...

  6. 继续过中等难度.0309

      .   8  String to Integer (atoi)    13.9% Medium   . 151 Reverse Words in a String      15.7% Mediu ...

  7. 每天一道LeetCode-----寻找给定字符串中重复出现的子串

    Repeated DNA Sequences 原题链接Repeated DNA Sequences 在给定字符串中寻找重复出现的序列,每个序列长度为10 可以采用unordered_map记录每个序列 ...

  8. leetcode 214. Shortest Palindrome | 214. 最短回文串(Java)

    题目 https://leetcode.com/problems/shortest-palindrome/ 题解 看了 Related Topics - Rolling Hash 下的相关题目,看到了 ...

  9. [LeetCode] Power of Two 判断2的次方数

    Given an integer, write a function to determine if it is a power of two. Example 1: Input: 1 Output: ...

最新文章

  1. [No0000160]常用C# 正则表达式大全
  2. Failed to install*.apk on device '': timeout
  3. 如何选择版本控制系统之二
  4. JSP Cookie处理
  5. Unity3D ShaderLab 菲涅耳内轮廓
  6. 联想一体机电源键不亮_联想/兄弟打印机复印一体机激光器清洁教程
  7. Bootstrap入门(二十九)JS插件6:弹出框
  8. 学习网站(不断更新)
  9. mac 命令失效问题 命令不存在 : command not found
  10. C# - 企业框架下的存储过程输出参数
  11. Qt linux双屏,qt5 多屏显示
  12. JavaScript函数重载(js函数重载)
  13. linux 锐捷 dns,锐捷Linux
  14. 论坛介绍 | COSCon'22 开源文化
  15. 常见面试题汇总 —— C语言
  16. 一个由“2020年1月7日 京东出现的重大 Bug 漏洞“引起的思考......
  17. 理解浏览器的历史记录
  18. HTML中的“雪碧图“详解
  19. 从0开始学递归和分治
  20. HaaS-Python实现智能水族生态控制器

热门文章

  1. Cinemachine(四)在路径/轨道上移动的摄像头(Cinemachine Dolly Camera,Path And Cart)
  2. python 摄像头拍照是反的,Python/OpenCV网络摄像头向后移动
  3. BaseRpm 机械角度 电角速度
  4. 快速获取商品页面原数据【淘宝】
  5. 英语单词计算机房怎么写,2014新版PEP四年级单词表 1
  6. 会计学原理学习笔记——第三章——账户与复式记账(3.1资金筹集业务的核算——投入资本的核算)
  7. 从零搭建本地PLC仿真环境:SIMATIC_PLCSIM_Advanced、Portal、KEPServer、OPCUA客户端工具
  8. H3C S5500-SI LLDP基本功能的典型配置
  9. 2020年最热门化妆品、护肤品一览表
  10. 大学计算机领域论文,计算机科学技术的应用领域简述论文.doc