leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0647.cpp (561B)


0 class Solution { 1 public: 2 int countSubstrings(const string &s) { 3 const int size = s.size(); 4 int res = size, low, high; 5 for (int i = 0; i < size; i++) { 6 low = i - 1, high = i + 1; 7 while (low >= 0 && high < size) { 8 if (s[low--] != s[high++]) break; 9 res++; 10 } 11 12 low = i - 1, high = i; 13 while (low >= 0 && high < size) { 14 if (s[low--] != s[high++]) break; 15 res++; 16 } 17 } 18 return res; 19 } 20 };