End of Year Sale: Use Coupon Code END2025 to Get Extra 25% Off.
03DAYS
:
22HOURS
:
42MINUTES
:
11SECONDS
Leetcode Problem 647. Palindromic Substrings
647. Palindromic Substrings
Leetcode Solutions
Expand Around Possible Centers
Initialize a count variable to 0 to keep track of palindromic substrings.
Iterate through the string with a loop, treating each index as the center of a potential palindrome.
For each center, expand outwards for odd and even length palindromes:
a. For odd-length palindromes, set left and right pointers to the center index.
b. For even-length palindromes, set the left pointer to the center index and the right pointer to the next index.
While the left and right pointers are within the bounds of the string and the characters at these pointers are equal, increment the count and move the pointers outward.