This is literally the same loop as LeetCode 5 — same 2n−1 centers, same two
pointers starting together and moving apart, same while (s[l] == s[r]). Only the
accumulator changes: LeetCode 5 keeps a maximum, this one keeps a counter. That
single-line swap is the whole reason both problems sit in the syllabus, and it works because the
expansion has a hidden bijection built into it: every palindromic substring has exactly one center, so
incrementing once per successful widen counts each substring exactly once, with no dedup pass and no
set. The n−1 gap centers are still the part people drop — forget them
and "abba" answers 4 instead of 6.
count++ per successful expansion is already
deduplicated. Swap that line for if (r-l+1 > bestLen) and you have LeetCode 5.