C++ 代码
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
bool check(int x)
{
for(int i=0;i+x<n;i++)
{
if(s.find(s.substr(i,x))!=s.rfind(s.substr(i,x)))return 0;//从前往后找的位置不等于从后往前找的位置 就表示有重复
}
return 1;
}
int main()
{
cin>>n;
cin>>s;
int l=1,r=101;
while(l<r)
{
int mid=(l+r)>>1;
if(check(mid))r=mid;
else l=mid+1;
}
cout<<l;
return 0;
}