#include
#include
#include
#include<unordered_map>
using namespace std;
vector getlen(string s, vector &vec)
{
vector res;
unordered_map<string, int> mapstr;
for (auto x : vec)
{
mapstr[x]++;//hashmap竟然可以直接这么用
}
int len = vec[0].size();
int n = vec.size();
for (int i = 0; i <=(int)s.size() - lenn; i++)
{
unordered_map<string, int> countstr;
int j = 0;
for (j = 0; j < n; j++)
{
string str = s.substr(i + jlen, len);
if (!mapstr.count(str))
break;
countstr[str]++;
if (countstr[str] > mapstr[str])
{
break;
}
}
if (j == n)
{
res.push_back(i);
}
}
return res;
}
int main()
{
unordered_map<int, int> mapint;
string str = “barfoothefoobarman”;
vector strvec{ “foo”,“bar” };
getlen(str, strvec);
system(“pause”);
return 0;
}
30. Substring with Concatenation of All Words 串联所有单词的子串
最新推荐文章于 2019-10-13 21:47:45 发布