Class Solution
-
- All Implemented Interfaces:
public final class Solution3579 - Minimum Steps to Convert String with Operations.
Hard
You are given two strings,
word1andword2, of equal length. You need to transformword1intoword2.For this, divide
word1into one or more contiguous substring. For each substringsubstryou can perform the following operations:Replace: Replace the character at any one index of
substrwith another lowercase English letter.Swap: Swap any two characters in
substr.Reverse Substring: Reverse
substr.
Each of these counts as one operation and each character of each substring can be used in each type of operation at most once (i.e. no single index may be involved in more than one replace, one swap, or one reverse).
Return the minimum number of operations required to transform
word1intoword2.Example 1:
Input: word1 = "abcdf", word2 = "dacbe"
Output: 4
Explanation:
Divide
word1into"ab","c", and"df". The operations are:For the substring
"ab",For the substring
"c"do no operations.For the substring
"df",
Example 2:
Input: word1 = "abceded", word2 = "baecfef"
Output: 4
Explanation:
Divide
word1into"ab","ce", and"ded". The operations are:For the substring
"ab",For the substring
"ce",For the substring
"ded",
Example 3:
Input: word1 = "abcdef", word2 = "fedabc"
Output: 2
Explanation:
Divide
word1into"abcdef". The operations are:For the substring
"abcdef",
Constraints:
1 <= word1.length == word2.length <= 100word1andword2consist only of lowercase English letters.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegerminOperations(String word1, String word2)-
-
Method Detail
-
minOperations
final Integer minOperations(String word1, String word2)
-
-
-
-