DEV Community

Paolo Ventura
Paolo Ventura

Posted on

100 algos in 100 days (Day 14)

Longest Substring that is a Palindrome

https://leetcode.com/problems/longest-palindromic-substring/submissions/

I managed to get the brute force quite quickly. Double iteration getting all the substrings. Greedily add them if longer than current longest substring.

How to make a more efficient solution... that is the question!

I quite like this recursive helper function I used for string reversal:


function reverseString(str) {
  if (str === ""){
    return "";}
  else{
    return reverseString(str.substr(1)) + str.charAt(0);}
}

Enter fullscreen mode Exit fullscreen mode

Top comments (0)