Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions 5.LongestPalindromicSubstring.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Solution {
public:
string longestPalindrome(string s) {
string ans="";
int st=0,end=0,len=0;
for(int i=0;i<s.size();i++){
int l=i,h=i;
while(l>=0 && h<s.size() && s[l]==s[h]){
if(h-l+1>len){
len=h-l+1;
st=l,end=h;
}
l--,h++;
}
l=i,h=i+1;
while(l>=0 && h<s.size() && s[l]==s[h]){
if(h-l+1>len){
len=h-l+1;
st=l,end=h;
}
h++,l--;
}
}
for(int i=st;i<=end;i++){
ans+=s[i];
}
return ans;
}
};
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ Once done kindly update the README.md file by updating the Problems : by adding
<li>1832. Check if the Sentence Is Pangram. [Easy]</li>
<li>2007. Find Original Array From Doubled Array. [Medium]</li>
<li>2095. Delete the Middle Node of a Linked List. [Medium]</li>
<li>5. Longest Palindromic Substring [Medium].</li>
</ul>
<br>
<hr>
Expand Down