文章标题
来源:互联网 发布:2017怎么开手机淘宝店 编辑:程序博客网 时间:2024/06/06 14:09
【题目】
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且出现超过1次的子串。
【算法】
需要用的【substr】函数
str.substr(startpos, length);
startpos 是起始字符的序号
length 是[从 startpos 开始]取的字符串长度(包括startpos )。
构造hash表。
【code】
class Solution {public: vector<string> findRepeatedDnaSequences(string s) { vector<string>res; map<string,int>mp; map<string,int>::iterator ml; for (int i = 9; i < s.size(); i++) { string stmp = s.substr(i-9,10); if(mp.count(stmp)) mp[stmp] ++; else mp[stmp] = 1; } for (ml = mp.begin(); ml!=mp.end(); ml++) { if(ml->second>1) res.push_back(ml->first); } return res; }};
0 0
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 整站开发流程概述
- C++Primer 第3章笔记整理
- 从零开始搭建Raspberry Pi机器视觉编程环境
- [从头读历史] 第246节 夏商与西周
- Bitmap的加载和缓存
- 文章标题
- 记一次css属性覆盖的问题
- Recurrent Neural Networks Tutorial
- 利用Emgu.CV实现人脸识别详解 (C#)--附源码
- Android 更新UI的两种方法——handler和runOnUiThread()
- 1067. Sort with Swap(0,*)
- Java之心跳机制
- 7.2节练习
- WPF DataGridHyperlinkColumn