c++ | easy | short
\n\n# Code\n\nclass Solution {\npublic:\n   int countSubstrings(string s, string t) {\n        int res = 0 ;\n        for (int i = 0; i < s.length(); ++i)\n    
\n\n# Code\n```\nclass Solution {\npublic:\n   int countSubstrings(string s, string t) {\n        int res = 0 ;\n        for (int i = 0; i < s.length(); ++i)\n            res += helper(s, t, i, 0);\n        for (int j = 1; j < t.length(); ++j)\n            res += helper(s, t, 0, j);\n        return res;\n    }\n\n    int helper(string s, string t, int i, int j) {\n        int res = 0, pre = 0, cur = 0;\n        for (int n = s.length(), m = t.length(); i < n && j < m; ++i, ++j) {\n            cur++;\n            if (s[i] != t[j])\n                pre = cur, cur = 0;\n            res += pre;\n        }\n        return res;\n    }\n};\n```
['C++']