Description

Given a string s, return the number of palindromic substrings in it. A substring is a contiguous sequence of characters.

Examples

Input:s = "abc"
Output:3
Explanation:

"a", "b", "c" are palindromes.

Input:s = "aba"
Output:4
Explanation:

The palindromic substrings are: "a" (index 0), "b" (index 1), "a" (index 2), and "aba" (the entire string). Each single character is a palindrome, and "aba" reads the same forwards and backwards.

Input:s = "racecar"
Output:10
Explanation:

The palindromic substrings are: "r", "a", "c", "e", "c", "a", "r" (7 single characters), "cec" (center palindrome), "aceca" (longer center palindrome), and "racecar" (the entire string which is a palindrome).

Constraints

  • 1 ≤ s.length ≤ 1000

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!