代码拉取完成,页面将自动刷新
class Solution
{
private:
int count[1000];
int countSize;
map<string, int> index;
vector<int> ret;
public:
vector<int> findSubstring(string S, vector<string> &L)
{
ret.clear();
if (L.size() == 0)
return ret;
index.clear();
countSize = 0;
for(int i = 0; i < L.size(); i++)
if (index.count(L[i]) > 0)
count[index[L[i]]]++;
else
{
index[L[i]] = countSize;
count[countSize++] = 1;
}
int step = L[0].size();
vector<int> a;
for(int i = 0; i < step; i++)
{
a.clear();
for(int j = i; j < S.size(); j += step)
{
if (j + step <= S.size())
{
string s(S, j, step);
if (index.count(s) > 0)
a.push_back(index[s]);
else
a.push_back(-1);
}
}
int beg = -1;
int end = 0;
int size = L.size();
while(end < a.size())
{
if (a[end] != -1)
{
if (count[a[end]] > 0)
{
if (beg == -1)
beg = end;
size--;
count[a[end]]--;
}
else
{
while(beg < end)
{
count[a[beg]]++;
size++;
if (a[beg++] == a[end])
break;
}
count[a[end]]--;
size--;
}
}
else
{
size = L.size();
if (beg != -1)
{
for(int i = beg; i < end; i++)
count[a[i]]++;
}
beg = -1;
}
end++;
if (size == 0)
{
ret.push_back(beg * step + i);
size++;
count[a[beg]]++;
beg++;
}
}
if (beg != -1)
{
for(int i = beg; i < end; i++)
count[a[i]]++;
}
}
return ret;
}
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。