---
# System prepended metadata

title: 0647. Palindromic Substrings
tags: [Leetcode, FaceBook, Medium, Palindrome]

---

# 0647. Palindromic Substrings
###### tags: `Leetcode` `FaceBook` `Medium` `Palindrome`
Link: https://leetcode.com/problems/palindromic-substrings/
## 思路
和[0005. Longest Palindromic Substring](https://hackmd.io/m_2zyr2OSpaFz53HPXrl8A)思路一样
Expand around center
## Code
```java=
class Solution {
    public int countSubstrings(String s) {
        int ans = 0;
        for(int i=0;i < s.length();i++){
            ans += computeSubstring(s,i,i);
            ans += computeSubstring(s,i,i+1);
        }
        return ans;
    }
    public int computeSubstring(String s, int lo, int hi){
        int ans = 0;
        while(lo>=0 && hi<s.length()){
            if(s.charAt(lo)!=s.charAt(hi)){
                break;
            }
            lo--;
            hi++;
            ans++;
        }
        return ans;
    }
}
```