Repeated DNA sequences
All DNA are composed of a series of nucleotides abbreviated as a, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it's 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"].
Each string of length 10 is searched for by map to determine if it has occurred before.
Using hash can reduce the complexity of space.
classSolution { Public: Vector<string> findrepeateddnasequences (strings) {vector<string>ret; if(S.size () <Ten) returnret; Unordered_map<size_t,int>m; Hash<string>STRH; for(inti =0; I <= s.size ()-Ten; i + +) { stringSub = S.substr (i,Ten); M[STRH (sub)]++; if(M[STRH (sub)] = =2) {//Find RepeatRet.push_back (sub); } } returnret; }};
"Leetcode" 187. Repeated DNA sequences