From 4f5f4f076dd493310c14a83495296793aaba855e Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Sat, 13 Jan 2024 00:00:34 -0500 Subject: 1347 --- 1347/main.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 1347/main.py diff --git a/1347/main.py b/1347/main.py new file mode 100755 index 0000000..ba3f0a5 --- /dev/null +++ b/1347/main.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python + + +class Solution: + def minSteps(self, s: str, t: str) -> int: + count_s = [0] * 26 + count_t = [0] * 26 + + for char in s: + count_s[ord(char) - ord("a")] += 1 + + for char in t: + count_t[ord(char) - ord("a")] += 1 + + steps = 0 + for i in range(0, 26): + steps += abs(count_s[i] - count_t[i]) + + return steps // 2 + + +def main(): + solution = Solution() + print(solution.minSteps("bab", "aba")) + print(solution.minSteps("leetcode", "practice")) + print(solution.minSteps("anagram", "mangaar")) + + +if __name__ == "__main__": + main() -- cgit v1.2.3