由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 请问leetcode Substring with Concatenation of All Words为什么runtime error
相关主题
请问Substring with Concatenation of All Words?Count Inversions 求助
请教一道题目facebook一题
leetcode是不是最近有点问题?这个题目难度在leetcode里算什么
求DEBUG Substring with Concatenation of All Wordsfinds all repeated substrings in the string --- YAHOO interview question
帮忙看看为撒 leetcode OJ time out "Substring with Concatenation of All Words "讨论一道G的题find longest substring which contains just two unique characters.
Substring with Concatenation of All Words 还有更简洁的解法吗?专家们,find the longest common substring of two strings
Leetcode的Substring with Concatenation of All Words超时。Permutation leetcode-
Leetcode第30题真心不容易wildcard matching 大case runtime error
相关话题的讨论汇总
话题: wordlen话题: temp话题: int
进入JobHunting版参与讨论
1 (共1页)
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;
}
1 (共1页)
进入JobHunting版参与讨论
相关主题
wildcard matching 大case runtime error帮忙看看为撒 leetcode OJ time out "Substring with Concatenation of All Words "
讨论一道leetcode上面的题Substring with Concatenation of All Words 还有更简洁的解法吗?
报个微软的OfferLeetcode的Substring with Concatenation of All Words超时。
微软电面Leetcode第30题真心不容易
请问Substring with Concatenation of All Words?Count Inversions 求助
请教一道题目facebook一题
leetcode是不是最近有点问题?这个题目难度在leetcode里算什么
求DEBUG Substring with Concatenation of All Wordsfinds all repeated substrings in the string --- YAHOO interview question
相关话题的讨论汇总
话题: wordlen话题: temp话题: int