由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 求DEBUG Substring with Concatenation of All Words
相关主题
问大牛们一个Leetcode上的题Leetcode的Substring with Concatenation of All Words超时。
Substring with Concatenation of All Words 还有更简洁的解法吗?leetcode online judge Longest Palindromic Substring memory limit exceeded
请问Substring with Concatenation of All Words? Memory Limit Exceeded: Longest Palindromic Substring
Leetcode第30题真心不容易都来说说leetcode上无聊恶心的题吧
这个题目难度在leetcode里算什么请问leetcode Substring with Concatenation of All Words为什么runtime error
Substring with Concatenation of All Wordsleetcode-- scramble string
关于Leetcode: Substring with Concatenation of All Wordsleetcode上zigzag converstion那题怎么才能通过large?
帮忙看看为撒 leetcode OJ time out "Substring with Concatenation of All Words "IF语句&&前后换个顺序就超时!!!搞笑啊!!!
相关话题的讨论汇总
话题: map话题: int话题: sub话题: found话题: string
进入JobHunting版参与讨论
1 (共1页)
e***s
发帖数: 799
1
在LEETCODE OJ 的一题
You are given a string, S, and a list of words, L, that are all of the same
length. Find all starting indices of substring(s) in S that is a
concatenation of each word in L exactly once and without any intervening
characters.
For example, given:
S: "barfoothefoobarman"
L: ["foo", "bar"]
下面是我的代码,在small case 4ms 通过, big case Time Limit Exceeded,不知道
为什么,求解答。
vector findSubstring(string S, vector &L) {
// Start typing your C/C++ solution below
// DO NOT write int main() function

vector ret;
map map_count;
map map_found;
int l = L[0].length();
int total = L.size();
for (int i = 0; i < total; i++)
{
if (map_count.find(L[i]) != map_count.end())
map_count[L[i]]++;
else
map_count.insert(pair(L[i], 1));
}
int leastlength = S.length() - l * total;

for (int i = 0; i <= leastlength ; i++)
{
int index = i;
while (total > 0)
{
string sub = S.substr(index, l);
if (map_count.find(sub) == map_count.end())
break;
else if (map_found.find(sub) != map_found.end() && map_found
[sub] >= map_count[sub])
break;
else
{
if (map_found.find(sub) != map_found.end())
map_found[sub]++;
else
map_found.insert(pair(sub, 1));
total--;
index += l;
}
}

if(total == 0)
ret.push_back(i);
total = L.size();
map_found.clear();
}
return ret;
}
1 (共1页)
进入JobHunting版参与讨论
相关主题
IF语句&&前后换个顺序就超时!!!搞笑啊!!!这个题目难度在leetcode里算什么
Memory Limit Exceeded 错误Substring with Concatenation of All Words
finds all repeated substrings in the string --- YAHOO interview question关于Leetcode: Substring with Concatenation of All Words
请教一道题目帮忙看看为撒 leetcode OJ time out "Substring with Concatenation of All Words "
问大牛们一个Leetcode上的题Leetcode的Substring with Concatenation of All Words超时。
Substring with Concatenation of All Words 还有更简洁的解法吗?leetcode online judge Longest Palindromic Substring memory limit exceeded
请问Substring with Concatenation of All Words? Memory Limit Exceeded: Longest Palindromic Substring
Leetcode第30题真心不容易都来说说leetcode上无聊恶心的题吧
相关话题的讨论汇总
话题: map话题: int话题: sub话题: found话题: string