1class Solution {2public:3int countSubstrings(string s) {4int count = s.size();5for (int i = 0; i < s.size(); i++) {6int len1 = expand(s, i, i + 1);7int len2 = expand(s, i, i);89// every palindrome found has len/2 total number of palindromes10count += len1 / 2;11count += len2 / 2;12}13return count;14}1516int expand(string s, int i, int j) {17while (i >= 0 && j < s.size() && s[i] == s[j]) {18i--;19j++;20}21return j - i - 1;22}23};