解题思路:
(1)计算s的所有子字符串,并与t匹配
class Solution {
public:
int helper(string &str,string &t,int j) {
int count=0;
for(int i=0;i<=t.size()-j;i++) {
int cnt=0;
string temp=t.substr(i,j);
for(int k=0;k<j;k++) {
if(str[k]!=temp[k]) cnt++;
}
if(cnt==1) count++;
}
return count;
}
int countSubstrings(string s, string t) {
int count=0;
for(int i=0;i<s.length();i++) {
for(int j=1;j<=s.length()-i;j++) {
string str = s.substr(i,j);
count+=helper(str,t,j);
}
}
return count;
}
};