We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents e5ed7f3 + 5036ef6 commit fe93bfdCopy full SHA for fe93bfd
Medium/5. Longest Palindromic Substring/chiku011solution.cpp
@@ -0,0 +1,34 @@
1
+
2
3
+class Solution {
4
+public:
5
+ bool check (int i,int j , string s){
6
+ while(i<=j){
7
+ if(s[i] != s[j]){
8
+ return false;
9
+ }else{
10
+ i++;
11
+ j--;
12
+ }
13
14
+ return true;
15
16
+ string longestPalindrome(string s) {
17
+ int maxlen=0;
18
+ int index =0;
19
+ for(int i =0;i<s.size();i++){
20
+ for(int j =i;j<s.size();j++){
21
+ if(s[i]==s[j]){
22
+ bool ans = check(i,j,s);
23
+ if(ans){
24
+ if(j-i+1 > maxlen){
25
+ maxlen = j-i+1;
26
+ index =i;
27
28
29
30
31
32
+ return s.substr(index,maxlen);
33
34
+};
0 commit comments