java.lang.Object
g2101_2200.s2186_minimum_number_of_steps_to_make_two_strings_anagram_ii.Solution

public class Solution extends Object
2186 - Minimum Number of Steps to Make Two Strings Anagram II.<p>Medium</p> <p>You are given two strings <code>s</code> and <code>t</code>. In one step, you can append <strong>any character</strong> to either <code>s</code> or <code>t</code>.</p> <p>Return <em>the minimum number of steps to make</em> <code>s</code> <em>and</em> <code>t</code> <em><strong>anagrams</strong> of each other.</em></p> <p>An <strong>anagram</strong> of a string is a string that contains the same characters with a different (or the same) ordering.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;<strong>lee</strong>tco<strong>de</strong>&rdquo;, t = &ldquo;co<strong>a</strong>t<strong>s</strong>&rdquo;</p> <p><strong>Output:</strong> 7</p> <p><strong>Explanation:</strong></p> <ul> <li> <p>In 2 steps, we can append the letters in &ldquo;as&rdquo; onto s = &ldquo;leetcode&rdquo;, forming s = &ldquo;leetcode<strong>as</strong>&rdquo;.</p> </li> <li> <p>In 5 steps, we can append the letters in &ldquo;leede&rdquo; onto t = &ldquo;coats&rdquo;, forming t = &ldquo;coats<strong>leede</strong>&rdquo;.</p> </li> </ul> <p>&ldquo;leetcodeas&rdquo; and &ldquo;coatsleede&rdquo; are now anagrams of each other.</p> <p>We used a total of 2 + 5 = 7 steps.</p> <p>It can be shown that there is no way to make them anagrams of each other with less than 7 steps.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;night&rdquo;, t = &ldquo;thing&rdquo;</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> The given strings are already anagrams of each other. Thus, we do not need any further steps.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length, t.length <= 2 * 10<sup>5</sup></code></li> <li><code>s</code> and <code>t</code> consist of lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details