#647
Palindromic Substrings
pupil · 520 · lc medium +28 · verified · 72.6% accepted · 11,479 likes · top 82%
Description
Given a string s, count and return the total number of substrings that are palindromes (they read the same forwards and backwards). Each character by itself is always a palindromic substring.
Example 1:
Input: s = "abc"
Output: 3
Explanation: Three palindromic strings: "a", "b", "c".
Example 2:
Input: s = "aaa"
Output: 6
Explanation: Six palindromic strings: "a", "a", "a", "aa", "aa", "aaa".
Code
1
2
3