Palindromic Substrings
Description
Given a string, your task is to count how many palindromic substrings in this string.
The substrings with different start indexes or end indexes are counted as different substrings even they consist of same characters.
Example 1:
Example 2:
Note:
The input string length won't exceed 1000.
Solutions
My solution
The number of palindromic substrings in s[0..i]
is the number of palindromic substrings in s[0..i-1]
+ the number of palindromic substrings ending with s[i]
.
A substring s[i..j]
is palindromic if and only if s[i] == s[j]
and s[i+1..j-1]
is palindromic.
Optimal solution
(Not a dynamic programming solution)
Last updated