classSolution: defcountSubstrings(self, s: str, t: str) -> int: ans = 0 for i inrange(1, len(s) + 1): if i > len(t): return ans tmp_index = 0 tmp_s = [] tmp_t = [] while tmp_index + i <= len(s): tmp_s.append(s[tmp_index: tmp_index + i]) tmp_index += 1 tmp_index = 0 while tmp_index + i <= len(t): tmp_t.append(t[tmp_index: tmp_index + i]) tmp_index += 1 for sub_s in tmp_s: for sub_t in tmp_t: dif = 0 for cnt inrange(0, i): if dif > 1: break if sub_s[cnt] != sub_t[cnt]: dif += 1 if dif == 1: ans += 1 return ans
classSolution: defcountSubstrings(self, s: str, t: str) -> int: ans = 0 s_len, t_len = len(s), len(t) for i inrange(len(s)): for j inrange(len(t)): if s[i] != t[j]: left = right = 0 while i > left and j > left and s[i - left - 1] == t[j - left - 1]: left += 1 while i + right + 1 < s_len and j + right + 1 < t_len and s[i + right + 1] == t[j + right + 1]: right += 1 ans += (left + 1) * (right + 1) return ans