Skip to content

Commit 1270d7c

Browse files
Merge pull request begeekmyfriend#27 from pratikgl/master
Added C++ Implementation
2 parents 549b1fb + 3926f97 commit 1270d7c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
class Solution {
6+
public:
7+
string longestPalindrome(string s) {
8+
bool dp[1005][1005];
9+
int n = s.size();
10+
int strlen = 0, start;
11+
for(int i=n-1; i>=0; i--){
12+
for(int j=i; j<n; j++){
13+
dp[i][j] = false;
14+
if(s[i] == s[j] && (j-i<3 || dp[i+1][j-1])) {
15+
dp[i][j] = true;
16+
if(strlen < j-i+1){
17+
strlen = j-i+1;
18+
start = i;
19+
}
20+
}
21+
}
22+
}
23+
return s.substr(start, strlen);
24+
}
25+
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy