其他分享
首页 > 其他分享> > 187. Repeated DNA Sequences

187. 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.

Example:

Input: s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT"

Output: ["AAAAACCCCC", "CCCCCAAAAA"]

class Solution {
public:
vector findRepeatedDnaSequences(string s) {
set set_res,sequences;
int len = s.size();

    for(int i = 0; i + 9 < len; i++)
    {
        string temp = s.substr(i, 10);
        if(sequences.count(temp)) 
        {
            set_res.insert(temp);
        }
        else
        {
            sequences.insert(temp);
        }
    }
    
    return vector<string>(set_res.begin(), set_res.end());
}

};

后续优化,采用bitmap的方式减少存储。。。。。

标签:set,DNA,temp,int,res,Repeated,187,sequences
来源: https://www.cnblogs.com/qiaozhoulin/p/13376719.html