187.重复的dna序列

2019-01-22  本文已影响0人  Pagliacci_Joker

思路:

用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;


    }
};

上一篇 下一篇

猜你喜欢

热点阅读