mirror of
https://github.com/Manoj-HV30/dsa-competitive-programming.git
synced 2026-05-16 19:35:22 +00:00
24 lines
791 B
C++
24 lines
791 B
C++
class Solution{
|
|
public:
|
|
string LongestPalindrome(string s){
|
|
for(int length= s.size();i>0;i--){
|
|
for(int start = 0;start<=s.size()-length;start++){
|
|
if(check(s,start,start+length))
|
|
return s.substr(start,length);
|
|
}
|
|
}
|
|
}
|
|
private: bool check(string s, int i, int j){
|
|
int left = i;
|
|
int right = j-1;
|
|
while(left<right){
|
|
if(s[left]!=S[right])
|
|
return false;
|
|
left++;
|
|
right--;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
};
|