Return the number of palindromic substrings in s. Substrings at different positions count separately.
Every successful expansion step from one of the 2n − 1 centers is exactly one palindrome. Count them.
1function countSubstrings(s: string): number {2let count = 0;3const expand = (l: number, r: number) => {4while (l >= 0 && r < s.length && s[l] === s[r]) { count++; l--; r++; }5};6for (let i = 0; i < s.length; i++) {7expand(i, i);8expand(i, i + 1);9}10return count;11}
Centers at 0 and 0|1.
Space: play/pause · ←/→: step