diff --git a/leetcode/1347.MinimumNumberOfStepsToMakeTwoStringsAnagram/minimumNumberOfStepsToMakeTwoStringsAnagram.go b/leetcode/1347.MinimumNumberOfStepsToMakeTwoStringsAnagram/minimumNumberOfStepsToMakeTwoStringsAnagram.go new file mode 100644 index 0000000..4b3c117 --- /dev/null +++ b/leetcode/1347.MinimumNumberOfStepsToMakeTwoStringsAnagram/minimumNumberOfStepsToMakeTwoStringsAnagram.go @@ -0,0 +1,31 @@ +// https://leetcode.com/problems/minimum-number-of-steps-to-make-two-strings-anagram + +package main + +import ( + "fmt" +) + +func minSteps(s string, t string) int { + cnt := make([]int, 26) + for i := 0; i < len(s); i++ { + cnt[s[i]-'a']++ + cnt[t[i]-'a']-- + } + + result := 0 + for i := 0; i < 26; i++ { + if cnt[i] > 0 { + result += cnt[i] + } + } + + return result +} + +func main() { + s := "leetcode" + t := "practice" + + fmt.Println(minSteps(s, t)) +}