参考第5题h,一下子就ac掉了,这里有个解释
不过和第五题思想一样啦
public int countSubstrings(String s) { int count = 0; for (int i = 0; i <2*s.length()-1; i++) { int left = i/2; int right = i/2; if(i%2==1){ right++; } count+=getSub(s, left, right); } return count; } public int getSub(String s,int left,int right){ int count = 0; while(left>=0&&right<=s.length()-1&&s.charAt(left)==s.charAt(right)){ left--; right++; count++; } return count; }