From ec865b909c43f2c587e51f16d37442742f0e3408 Mon Sep 17 00:00:00 2001 From: shubham-marathe <117026759+shubham-marathe@users.noreply.github.com> Date: Sun, 30 Oct 2022 22:51:09 +0530 Subject: [PATCH] Create Longest Palindromic Substring.cpp --- CPP/Longest Palindromic Substring.cpp | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 CPP/Longest Palindromic Substring.cpp diff --git a/CPP/Longest Palindromic Substring.cpp b/CPP/Longest Palindromic Substring.cpp new file mode 100644 index 0000000..78c5c0e --- /dev/null +++ b/CPP/Longest Palindromic Substring.cpp @@ -0,0 +1,30 @@ +class Solution { +public: + string longestPalindrome(string s) { + int n=s.length(); + int maxLength=1; + int start=0; + int low,high; + for(int i=0;i=0 && s[i]==s[low]){ + low--; + } + while(high=0 && highmaxLength){ + maxLength=length; + start=low+1; + } + } + return s.substr(start,maxLength); + + } +};