mirror of
https://github.com/Manoj-HV30/dsa-competitive-programming.git
synced 2026-05-16 19:35:22 +00:00
Leetcode day 2 and 3
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
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;
|
||||
}
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user