Skip to content

Commit

Permalink
Create 2981. Find Longest Special Substring That Occurs Thrice I (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Dec 10, 2024
2 parents edc31d0 + b85bee2 commit 29548fc
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions 2981. Find Longest Special Substring That Occurs Thrice I
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class Solution {
public:
int maximumLength(string s) {
map<char,int>maps;
for( auto &a:s){
maps[a]++;
}
bool test=false;
for(auto &a:maps){
if(a.second>1)
test=true;

}
if(test==false)
return -1;
int res=-1;
map<string,int>tmp;
for(int i=0;i<s.size();i++){
int j=i+1;
tmp[s.substr(i,1)]++;
while(j<s.size() && s[i]==s[j] ){
tmp[s.substr(i,j-i+1)]++;
j++;

}
}
for(auto &a:tmp){
if(a.second>=3){
int i=a.first.size();
if(i>res){
res=a.first.size();
}
}
}
return res;
}
};

0 comments on commit 29548fc

Please sign in to comment.