Skip to content

Latest commit

 

History

History
117 lines (47 loc) · 2.07 KB

File metadata and controls

117 lines (47 loc) · 2.07 KB

中文文档

Description

Strings A and B are K-similar (for some non-negative integer K) if we can swap the positions of two letters in A exactly K times so that the resulting string equals B.

Given two anagrams A and B, return the smallest K for which A and B are K-similar.

Example 1:

Input: A = "ab", B = "ba"

Output: 1

Example 2:

Input: A = "abc", B = "bca"

Output: 2

Example 3:

Input: A = "abac", B = "baca"

Output: 2

Example 4:

Input: A = "aabc", B = "abca"

Output: 2

Note:

    <li><code>1 &lt;= A.length == B.length &lt;= 20</code></li>
    
    <li><code>A</code> and <code>B</code> contain only lowercase letters from the set <code>{&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;, &#39;f&#39;}</code></li>
    

Solutions

Python3

Java

...