一道俩个字符串是否包含的问题

来源:互联网 发布:mysql注释 编辑:程序博客网 时间:2024/06/06 14:12

1.采用遍历的方式

bool CompareSting(string LongStr,string ShortStr){int i=0,j=0;for (i=0;i<ShortStr.length();i++){for (j=0;j<LongStr.length();j++){if(ShortStr[i]==LongStr[j])break;}if (j==LongStr.length()){cout<<"false";return false;}}cout<<"true";return true;}


 

 上述代码的时间复杂度为O(n*m),显然,时间开销太大,我们需要找到一种更好的办法。