您的位置:首页 > 大数据 > 人工智能

Return if string t contains all chars in s

2014-10-30 07:12 232 查看
bool isSubsetOf(const string& s, const string& t)
{
if(s.length() > t.length())
return false;

vector<int> table(256,0);
int cur = 0;
for(int i=0;i<s.length();++i)
{
if(table[s[i]] > 0)  // if the char has been checked in t, decrease the counter by 1
{
--table[s[i]];
continue;
}
else if(cur == t.length())
return false;

while(cur < t.length())
{
if(t[cur] != s[i])
{
++table[t[cur]];
++cur;
}
else
{
++cur;
break;
}
}
}
return true;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Google string