当前位置:网站首页>[string] judge whether S2 is the rotation string of S1

[string] judge whether S2 is the rotation string of S1

2022-06-12 03:00:00 I'm not xiaohaiwa~~~~

Normal operation

bool isRotation(string s1, string s2)
{
    
    if(s1.length()!=s2.length())
        return false;
    bool ret=false;


    for(int i=0;i<s1.length();i++)
    {
    
        string temp=s1.substr(0,i+1);
// cout<<temp<<endl;
        string temp2=s1.substr(i+1,(s1.length()-i+1));
// cout<<temp2<<endl;
        string str=temp2+temp;
        if(str==s2)
        {
    
            cout<<str<<endl;
            return true;
        }
    }

    return ret;
}

原网站

版权声明
本文为[I'm not xiaohaiwa~~~~]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203011114355337.html