leetcode:Repeated DNA Sequences

class Solution {
public:
   char hash[1024*1024];
    vector<string> findRepeatedDnaSequences(string s) {
        vector<string> res;
        if(s.size()<10)
            return res;
        char convertor[26];
        convertor[0] = 0;
        convertor[2] = 1;
        convertor[6] = 2;
        convertor[19] = 3;
        memset(hash,'0',sizeof(hash));
        for(int i=0;i<s.size()-9;i++)
        {
            string temp = s.substr(i,10);
            int val =0 ;
            for(int j=0;j<10;j++)
            {
                val = (val<<2)+convertor[temp[j]-'A'];
            }
            if((hash[val]-'0')==1)
                res.push_back(temp);
            hash[val] = hash[val]+1;
        }
        return res;
        
    }
};

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章