Untitled

 avatar
unknown
plain_text
3 months ago
439 B
4
Indexable
class Solution {
    int ans = 0;
    public int countSubstrings(String S) {
        for(int i=0;i<S.length();i++){
            expandAlongCenter(S,i,i);
            expandAlongCenter(S,i,i+1);
        }
        return ans;
    }
    private void expandAlongCenter(String s,int l,int r){
        while(l>=0 && r<s.length() && s.charAt(l)==s.charAt(r)){
            ans++;
            l--;
            r++;
        }
    }
}
Editor is loading...
Leave a Comment