美文网首页
187.重复的dna序列

187.重复的dna序列

作者: Pagliacci_Joker | 来源:发表于2019-01-22 20:49 被阅读0次

思路:

用setA记录不同的字符串子串

用setB对于超过1个的字符串子串进行去重

代码:

class Solution {
public:
    vector<string> findRepeatedDnaSequences(string s) {

        vector<string> res;
        set<string> subStringSet;
        set<string> resStringSet;

        int leftkey = 0;
        int rightkey = 10;
        int lenth = s.length();
        while (leftkey + rightkey <= lenth) {
            string substring = s.substr(leftkey, rightkey);
            if (subStringSet.find(substring) != subStringSet.end()) {
                if (resStringSet.find(substring) == resStringSet.end()) {
                    res.push_back(substring);
                    resStringSet.insert(substring);
                }
            } else {
                subStringSet.insert(substring);
            }
            leftkey++;

        }
        return res;


    }
};

相关文章

网友评论

      本文标题:187.重复的dna序列

      本文链接:https://www.haomeiwen.com/subject/sqgrjqtx.html