[leetcode] 187. Repeated DNA Sequences 解题报告
2016-05-05 14:24
561 查看
题目链接: https://leetcode.com/problems/repeated-dna-sequences/
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,
思路: 一个简单的hash表就可以搞定, 居然这么简单就过了, 也有点太水了吧.
代码如下:
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"].
思路: 一个简单的hash表就可以搞定, 居然这么简单就过了, 也有点太水了吧.
代码如下:
class Solution { public: vector<string> findRepeatedDnaSequences(string s) { if(s.size() < 10) return vector<string>(); unordered_map<string, int> hash; vector<string> result; for(int i = 0; i < s.size()-9; i++) { string str = s.substr(i, 10); if(hash.count(str) && hash[str] < 2) result.push_back(str); hash[str]++; } return result; } };
相关文章推荐
- android rawquery和query的比较
- UItextfield详解 for ios
- 去除UITableView底部多余行及分割线
- 133 - The Dole Queue
- 如何修改Bluetooth link supervision timeout (基于CSR BC4/5)
- UI设计风格的变化
- GradleUserGuide中文版 21)Java插件 22)War插件
- 大数据技术可视化之Hue
- Hibernate利用Query接口进行HQL查询
- UIAlertController中TextField的用法
- UIBezierPath和CAShapeLayer画各种图形
- cf450B. Jzzhu and Sequences
- GradleUserGuide中文版 19)Plugins 20)插件规范 21)Java插件
- UI切图那点事儿
- hdu3434 Sequence Adjustment
- UiAutomator Android 的自动测试框架(UiAutomator 快速调试)
- UI界面基础如何用鼠标控制物体移动
- GradleUserGuide中文版 16)Ant插件 17)Logging 18)Daemon 19)Plugins
- 关于UIView用户交互相关的属性和方法
- 关于UIView用户交互相关的属性和方法