讨论: 如果有人吃前妻/前夫的醋# Piebridge - 鹊桥
a*0
1 楼
class Solution {
public:
vector findRepeatedDnaSequences(string s) {
int map[4];
std::fill(map, map+4, 0);
vector res;
set keySet;
multimap mmap;
if(s.size()<10) return res;
for(int i=0;i map[toInt(s[i])]++;
if(i>=9){
if(i>=10){
map[toInt(s[i-10])]--;
}
string ss=toString(map);
keySet.insert(ss);
mmap.insert(make_pair(ss, i));
}
}
for(auto key: keySet){
if(mmap.count(key)>1){
auto ret=mmap.equal_range(key);
for(auto i=ret.first; i!=ret.second; i++){
res.push_back(s.substr(i->second-9, 10));
}
}
}
return res;
}
int toInt(char c){
switch(c){
case 'A': return 0;
case 'C': return 1;
case 'G': return 2;
case 'T': return 3;
}
return 4;
}
std::string toString(int a[]){
std::stringstream ss;
ss << 'A' << a[0];
ss << 'C' << a[1];
ss << 'G' << a[2];
ss << 'T' << a[3];
return ss.str();
}
};
Output Limit Exceeded:怎么破?
public:
vector
int map[4];
std::fill(map, map+4, 0);
vector
set
multimap
if(s.size()<10) return res;
for(int i=0;i
if(i>=9){
if(i>=10){
map[toInt(s[i-10])]--;
}
string ss=toString(map);
keySet.insert(ss);
mmap.insert(make_pair(ss, i));
}
}
for(auto key: keySet){
if(mmap.count(key)>1){
auto ret=mmap.equal_range(key);
for(auto i=ret.first; i!=ret.second; i++){
res.push_back(s.substr(i->second-9, 10));
}
}
}
return res;
}
int toInt(char c){
switch(c){
case 'A': return 0;
case 'C': return 1;
case 'G': return 2;
case 'T': return 3;
}
return 4;
}
std::string toString(int a[]){
std::stringstream ss;
ss << 'A' << a[0];
ss << 'C' << a[1];
ss << 'G' << a[2];
ss << 'T' << a[3];
return ss.str();
}
};
Output Limit Exceeded:怎么破?