Total accepted:32259 Total submissions:142733 difficulty:medium
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"].
classSolution { Public: Vector<string> findrepeateddnasequences (strings) {intS_size =s.size (); Vector<string>Res; if(s_size<Ten){ returnRes; } unordered_map<string,pair<BOOL,BOOL>>Umap; stringstr = S.SUBSTR (0,Ten); UMAP[STR]= Make_pair (true,false); for(intI=Ten; i<s_size;i++) {str.erase (Str.begin ()); Str.push_back (S[i]); if(umap[str].first) {if(!Umap[str].second) {res.push_back (str); Umap[str].second=true; } }Else{UMAP[STR]= Make_pair (true,false); } } returnRes; }};
Next challenges: (E) Reverse Bits (m) Sparse Matrix multiplication (m) Maximum Product of Word Lengths
Repeated DNA sequences