算法1
二分
参考文献
C++ 代码
#include<bits/stdc++.h>
using namespace std;
int n;
string str;
bool check(int mid)
{
unordered_set<string> hash;
for (int i=0; i+mid-1<str.size();i++){
auto s=str.substr(i, mid);
if(hash.count(s))return false;
hash.insert(s);
}
return true;
}
int main()
{
cin>>n;
cin>>str;
int l=1,r=n;
while(l<r){
int mid=l+r>>1;
if (check(mid))r=mid;
else l=mid+1;
}
cout<<r;
}
大佬 I+mid-1是为什么
+1吧,不就是二分吗
抽风大佬,为什么查询完后要将字符串插入到哈希表中呢?
正版抽风
orz
sto