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)


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