# 1347. Minimum Number of Steps to Make Two Strings Anagram ###### tags: `Leetcode` `Medium` `TikTok` ## Code ```python= class Solution: def minSteps(self, s: str, t: str) -> int: countS = collections.Counter(s) countT = collections.Counter(t) ans = 0 for char in countS.keys(): ans += max(0, countS[char]-countT[char]) return ans ``` ```java= class Solution { public int minSteps(String s, String t) { int ans = 0; char[] sArray = s.toCharArray(); char[] tArray = t.toCharArray(); int[] sFreq = new int[26]; int[] tFreq = new int[26]; for(int i = 0;i < s.length();i++){ sFreq[sArray[i]-'a']++; tFreq[tArray[i]-'a']++; } for(int i = 0;i < 26;i++){ ans += Math.abs(sFreq[i]-tFreq[i]); } return ans/2; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up