Back to Palindrome
Palindrome
Medium

Palindromic Substrings

LAB

Return the number of substrings of s that are palindromes.

EXAMPLES

Example 1
Input
{
  "s": "abc"
}

Output
3

FUNCTION SHAPE

s: stringint
SOLUTION NOTE

This is the same idea as Longest Palindromic Substring. We can either expand from centers or use DP to count all palindromic substrings.

Open on LeetCode
00:00
3 local tests readyRun with ⌘/Ctrl + Enter. Your code stays in this browser.

Runs solve(...) locally in a browser worker. SWE Playbook does not submit your code. Only run code you trust; Python code may access the network.