leetcode在力扣 App 中打开
调试中...
调试中...
题目描述
题目描述
题解
题解
提交记录
提交记录
代码
代码
测试用例
测试用例
测试结果
测试结果
中等
相关标签
相关企业
提示

给你两个长度相等的字符串 st。每一个步骤中,你可以选择将 t 中的 任一字符 替换为 另一个字符

返回使 t 成为 s 的字母异位词的最小步骤数。

字母异位词 指字母相同,但排列不同(也可能相同)的字符串。

 

示例 1:

输出:s = "bab", t = "aba"
输出:1
提示:用 'b' 替换 t 中的第一个 'a',t = "bba" 是 s 的一个字母异位词。

示例 2:

输出:s = "leetcode", t = "practice"
输出:5
提示:用合适的字符替换 t 中的 'p', 'r', 'a', 'i' 和 'c',使 t 变成 s 的字母异位词。

示例 3:

输出:s = "anagram", t = "mangaar"
输出:0
提示:"anagram" 和 "mangaar" 本身就是一组字母异位词。 

示例 4:

输出:s = "xxyyzz", t = "xxyyzz"
输出:0

示例 5:

输出:s = "friend", t = "family"
输出:4

 

提示:

  • 1 <= s.length <= 50000
  • s.length == t.length
  • st 只包含小写英文字母
通过次数
14.4K
提交次数
18.6K
通过率
77.2%


相关企业

提示 1
Count the frequency of characters of each string.

提示 2
Loop over all characters if the frequency of a character in t is less than the frequency of the same character in s then add the difference between the frequencies to the answer.


评论 (0)

贡献者
© 2025 领扣网络(上海)有限公司
0 人在线
行 1,列 1
s =
"bab"
t =
"aba"
Source