Longest Palindrome Solution on LeetCode

Day 28 of #100DaysOfCode: #DSA: Solve leetcode problem - Longest Palindrome(409) A palindrome string can be even/odd length so if the frequencies of letters are: 1. Even - we can use all of them to create palindrome string 2. Odd: - we can use frequency - 1 witch becomes even - we can leave one character for the middle approach: - hashmap to track freq of letters - iterate to the string - if freq is even just add to result - if freq is odd then add (freq - 1) to result - now in the last check - if hashmap contains only even freq return result - else return (result + 1) for middle character #Coding #Learing #CodingJourney

  • text

Without hashmaps this is so tricky

To view or add a comment, sign in

Explore content categories