Leetcode day 2 and 3

This commit is contained in:
2026-01-29 01:04:37 +05:30
parent 245116d181
commit 2ee49ea476
15 changed files with 204 additions and 1 deletions
+23
View File
@@ -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;
}
};