1 class Solution { 2 public: 3 int countSubstrings(string s) { 4 int n = s.size(), sum = 0; 5 for(int i = 0; i < n*2-1; i++) 6 { 7 int l = i / 2, r = i/2 + i%2; 8 while(l>=0 && r < n && s[l] == s[r]) 9 { 10 l--; 11 r++; 12 sum++; 13 } 14 } 15 return sum; 16 } 17 };