**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 | Input: "abc" |
Solution
Suppose there are n elements in the input string, then there would be 2*n-1
middle positions of possible palindrome.
For each center, we can check how many palindromes using this center.
Algorithm
Python
1 | def countPalindromes(s): |
Complexity
- Time Complexity: O(N^2)
- Space Complexity: O(1)
Not too hard, too lazy to explain.
If there is something incorrect, please let me know. And of course if you have some other good solutions, welcome to share with me...