Palindromic Substrings
https://leetcode.com/problems/palindromic-substrings/description/
Thoughts
Code
// @lc code=start
class Solution {
public:
int countSubstrings(string s) {
const int N = s.length();
int res = 0;
const auto ext = [&](string &s, int l, int r) {
while (l >= 0 && r < N && s[l--] == s[r++]) {
++res;
}
};
for (int i = 0; i < N; ++i) {
ext(s, i, i);
ext(s, i, i + 1);
}
return res;
}
};
// @lc code=endAnalysis
Last updated