Class Solution
-
- All Implemented Interfaces:
public final class Solution1638 - Count Substrings That Differ by One Character\.
Medium
Given two strings
sandt, find the number of ways you can choose a non-empty substring ofsand replace a single character by a different character such that the resulting substring is a substring oft. In other words, find the number of substrings insthat differ from some substring intby exactly one character.For example, the underlined substrings in
"computer"and"computation"only differ by the'e'/'a', so this is a valid way.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: 6
Explanation: The following are the pairs of substrings from s and t that differ by exactly 1 character:
("aba", "baba")
("aba", "baba")
("aba", "baba")
("aba", "baba")
("aba", "baba")
("aba", "baba")
The underlined portions are the substrings that are chosen from s and t.
Example 2:
Input: s = "ab", t = "bb"
Output: 3
Explanation: The following are the pairs of substrings from s and t that differ by 1 character:
("ab", "bb")
("ab", "bb")
("ab", "bb")
The underlined portions are the substrings that are chosen from s and t.
Constraints:
1 <= s.length, t.length <= 100sandtconsist of lowercase English letters only.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegercountSubstrings(String s, String t)-
-
Method Detail
-
countSubstrings
final Integer countSubstrings(String s, String t)
-
-
-
-