Their thinking

At the same time, the expansion can be divided into two cases. One is an odd palindrome string, such as ABCBC, and the other is an even palindrome string, such as Aabb. Both cases should be matched

Const expand = (left, right, s) => {let ret = 0; const expand = (left, right, s) => {let ret = 0; while (left >= 0 && right < s.length && s[left] === s[right]) { ret ++; left --; right ++; } return ret; } const countSubstrings = function(s) { let ret = 0; for (let i = 0; i < s.length; Ret += expand(I, I, s); ret += expand(I, I, s); ret += expand(i, i + 1, s); } return ret; };Copy the code