classSolution {publicintcountSubstrings(String s) {int result =0;for (int i =0; i <s.length(); i++) { result =helper(s, i, i, result); result =helper(s, i, i+1, result); }return result; }privateinthelper(String s,int l,int r,int result) {while (l >=0&& r <s.length() &&s.charAt(l) ==s.charAt(r)) { result++; l--; r++; }return result; }}