Class Solution
- java.lang.Object
-
- g0801_0900.s0854_k_similar_strings.Solution
-
public class Solution extends Object
854 - K-Similar Strings.Hard
Strings
s1ands2arek-similar (for some non-negative integerk) if we can swap the positions of two letters ins1exactlyktimes so that the resulting string equalss2.Given two anagrams
s1ands2, return the smallestkfor whichs1ands2arek-similar.Example 1:
Input: s1 = “ab”, s2 = “ba”
Output: 1
Example 2:
Input: s1 = “abc”, s2 = “bca”
Output: 2
Constraints:
1 <= s1.length <= 20s2.length == s1.lengths1ands2contain only lowercase letters from the set{'a', 'b', 'c', 'd', 'e', 'f'}.s2is an anagram ofs1.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-