c**z 发帖数: 669 | 1 leetcode 这道题大家帮忙看看为撒 time out
class Solution {
public:
vector findSubstring(string S, vector &L) {
// check border case
vector ret;
if ( L.empty() || S.empty() )
return ret;
int i = 0;
int j = 0;
int num = L.size();
int length = L[0].size();
map mapSrc;
map mapDest;
for( int i = 0 ; i
{
mapSrc[L[i]]++;
}
i=0;
while ( ( i + num * length - 1) < S.size())
{
j = i;
while( mapDest.size() < num )
{
string str = S.substr(j, length);
if ( mapSrc.find(str) == mapSrc.end() )
{
break;
}
else
{
auto iter = mapDest.find(str);
if ( iter == mapDest.end() || mapDest[str] < mapSrc[str]
)
{
mapDest[str]++;
}
else
{
break;
}
}
j = j + length;
}
if ( mapDest.size() == num )
{
ret.push_back(i);
}
mapDest.clear();
i = i +1;
}
return ret;
}
}; | P**********r 发帖数: 755 | 2 timeout是leetcode出错啦 你重新提交就好啦
【在 c**z 的大作中提到】 : leetcode 这道题大家帮忙看看为撒 time out : class Solution { : public: : vector findSubstring(string S, vector &L) { : // check border case : vector ret; : if ( L.empty() || S.empty() ) : return ret; : : int i = 0;
|
|