Class Solution
-
- All Implemented Interfaces:
public final class Solution3303 - Find the Occurrence of First Almost Equal Substring.
Hard
You are given two strings
sandpattern.A string
xis called almost equal toyif you can change at most one character inxto make it identical toy.Return the smallest starting index of a substring in
sthat is almost equal topattern. If no such index exists, return-1.A substring is a contiguous non-empty sequence of characters within a string.
Example 1:
Input: s = "abcdefg", pattern = "bcdffg"
Output: 1
Explanation:
The substring
s[1..6] == "bcdefg"can be converted to"bcdffg"by changings[4]to"f".Example 2:
Input: s = "ababbababa", pattern = "bacaba"
Output: 4
Explanation:
The substring
s[4..9] == "bababa"can be converted to"bacaba"by changings[6]to"c".Example 3:
Input: s = "abcd", pattern = "dba"
Output: \-1
Example 4:
Input: s = "dde", pattern = "d"
Output: 0
Constraints:
<code>1 <= pattern.length < s.length <= 3 * 10<sup>5</sup></code>
sandpatternconsist only of lowercase English letters.
Follow-up: Could you solve the problem if at most
kconsecutive characters can be changed?
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegerminStartingIndex(String s, String pattern)-
-
Method Detail
-
minStartingIndex
final Integer minStartingIndex(String s, String pattern)
-
-
-
-