leetcode

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

1638.cpp (472B)


      1 class Solution {
      2   public:
      3     int countSubstrings(const string &s, const string &t) {
      4         int res = 0;
      5         for (int i = 0; i < s.size(); ++i) {
      6             for (int j = 0; j < t.size(); ++j) {
      7                 for (int pos = 0, miss = 0; i + pos < s.size() && j + pos < t.size(); ++pos) {
      8                     if (s[i + pos] != t[j + pos] && ++miss > 1) break;
      9                     res += miss;
     10                 }
     11             }
     12         }
     13         return res;
     14     }
     15 };