Count Palindromic Substrings

Given a string s, return the total number of palindromic substrings in s. A substring is counted by position, so identical character sequences at different positions count separately. Pattern focus: Palindrome DP. This is the standard expansion/DP counting problem for palindromic intervals.

Input Format

s = input string

Output Format

number of palindromic substrings

Constraints

  • 0 <= s.length <= 1000
  • s contains lowercase English letters.

Examples

Example 1:

Input:

s = "abc"

Output:

3

Explanation:

Each single character is a palindrome.

Example 2:

Input:

s = "aaa"

Output:

6

Explanation:

The palindromic substrings are a, a, a, aa, aa, aaa.

Loading...
Count Palindromic Substrings - Dp Strings