📘
Palindromic Substrings
MediumDynamic Programming
Given a string s, return the number of palindromic substrings in it. A single character is a palindrome.
Example:
Input:
aaa
Output:
6
Reasoning:
- The string
aaahas 3 characters, so there are 3 single-character palindromic substrings:a,a,a. - There are also 2 two-character palindromic substrings:
aa,aa. - Additionally, there is 1 three-character palindromic substring:
aaa. - To find the total number of palindromic substrings, we sum these up: 3+2+1=6.
Constraints:
- 1 <= len(s) <= 1000
- s consists of lowercase English letters
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.