Created
June 8, 2018 14:21
-
-
Save s4553711/2f2e5e35857382b93092e9da7f769536 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int countSubstrings(string s) { | |
int ans = 0; | |
for (int i = 0; i < s.length();i++) { | |
ans += count(s, i, i); | |
ans += count(s, i, i+1); | |
} | |
return ans; | |
} | |
int count(string& s, int l, int r) { | |
int ans = 0; | |
while(l >= 0 && r < s.length() && s[l--] == s[r++]) ++ans; | |
return ans; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment