class Solution
{
public:
vector<string> findRepeatedDnaSequences(string s)
{
vector<string> vec;
if (s.size() <= 10)
{
return vec;
}
map<string, int> ma; //没要求有序的,也可以用无序的 unordered_map
int n = s.length();
for (int i = 0; i <= n - 10; ++i)
{
string sub = s.substr(i, 10);
ma[sub]++; //将子串加入到 ma 中,value 值 ++
}
for (const auto& m : ma)
{
if (m.second > 1)
{
vec.push_back(m.first); //大于 1 个的就 push_back 到返回的 vec 中
}
}
/* map<string, int>::iterator m = ma.begin(); //上面 auto 的类型
while (m!=ma.end())
{
if (m->second > 1)
{
vec.push_back(m->first);
}
++m;
}*/
return vec;
}
};
08-02
712