Count Substrings That Differ by One Character
Given two strings s and t, find the number of ways you can choose a non-empty substring of s and replace a single character by a different character such that the resulting substring is a substring of t. In other words, find the number of substrings in s that differ from some substring in t by exactly one character.
Return the number of substrings that satisfy the condition above.
A substring is a contiguous sequence of characters within a string.
Example 1
Input
s = "aba", t = "baba"Output
6There are 6 pairs of substrings from
s and t that differ by exactly one character.Example 2
Input
s = "ab", t = "bb"Output
3There are 3 pairs of substrings from
s and t that differ by exactly one character.Constraints
- 1 <= s.length, t.length <= 100
- s and t consist of lowercase English letters only.