m******3 发帖数: 346 | 1 在local没问题,code如下,可能是什么原因呢?
vector findSubstring(string s, vector& words) {
int wordLen = words[0].size();
map expectedCount;
map actualCount;
for (int i=0; i
expectedCount[words[i]] = expectedCount[words[i]]++;
}
vector res;
for (int i=0; i
int left = i;
int count = 0;
for (int j=i; j<=(int)s.length()-wordLen;j=j+wordLen) {
string str=s.substr(j, wordLen);
if (expectedCount.find(str)!=expectedCount.end()) {
actualCount[str]++;
if (actualCount[str]<=expectedCount[str]) {
count++;
} else {
while (actualCount[str]>expectedCount[str]) {
string temp = s.substr(left, wordLen);
actualCount[temp]=actualCount[temp]--;
if (actualCount[temp]
count--;
left=left+wordLen;
}
}
if (count==words.size()) {
res.push_back(left);
string temp = s.substr(left, wordLen);
actualCount[temp]=actualCount[temp]--;
if (actualCount[temp]
count--;
left=left+wordLen;
}
} else {
count=0;
actualCount.clear();
left=j+wordLen;
}
}
}
return res;
} |
|