题解 | #查找两个字符串a,b中的最长公共子串#

查找两个字符串a,b中的最长公共子串

https://www.nowcoder.com/practice/181a1a71c7574266ad07f9739f791506

#include <iostream>
using namespace std;

int main() {
    string str1,str2,res;
    cin>>str1>>str2;  
    if(str1.size()<str2.size()) swap(str1,str2);
    for(int i=str2.size();i>=0;i--){
        for(int j=0;j<str2.size()-i+1;j++){
            string temp=str2.substr(j,i);
            if(str1.find(temp)!=str1.npos){
                cout<<temp<<endl;
                return 0;
            }
        }        
    }

}

全部评论

相关推荐

09-24 17:30
门头沟学院 Java
点赞 评论 收藏
分享
熊大不大:微信也是华为旗下吧,我看我朋友也是华为工牌写wx
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务