1347. Minimum Number of Steps to Make Two Strings Anagram
https://leetcode.com/problems/minimum-number-of-steps-to-make-two-strings-anagram/
Given two equal-size strings s
and t
. In one step you can choose any character of t
and replace it with another character.
Return the minimum number of steps to make t
an anagram of s
.
An Anagram of a string is a string that contains the same characters with a different (or the same) ordering.
Example 1:
Example 2:
Example 3:
Example 4:
Example 5:
Constraints:
1 <= s.length <= 50000
s.length == t.length
s
andt
contain lower-case English letters only.
等长的字符串s和t,问让t的字符及频率变得和s一样且不要求顺序一样,至少需要替换t中多少个字符。统计s出现的字符和对应的频率并放到freq map中,遍历t当freq map出现负数时,意味着t中多了s中不存在的字符,又由于t和s等长,所以多了多少字符也就是少了同样数目的其它字符,也就是多了的字符数和要替换的字符数目一致,统计下来即结果。
Last updated
Was this helpful?