2186. Minimum Number of Steps to Make Two Strings Anagram II
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 73% Topics: Hash Table, String, Counting
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
import collections
# freq table
class Solution(object):
def minSteps(self, s, t):
"""
:type s: str
:type t: str
:rtype: int
"""
cnt1, cnt2 = collections.Counter(s), collections.Counter(t)
return sum((cnt1-cnt2).itervalues())+sum((cnt2-cnt1).itervalues())
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions