From 9c65fc3bcf15d44d92dc016a697ed44216332743 Mon Sep 17 00:00:00 2001 From: izatwin Date: Sun, 14 Jul 2024 08:34:30 -0400 Subject: [PATCH] 242 Valid Anagram --- easy/242 Valid Anagram/solution.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 easy/242 Valid Anagram/solution.py diff --git a/easy/242 Valid Anagram/solution.py b/easy/242 Valid Anagram/solution.py new file mode 100644 index 0000000..6f68285 --- /dev/null +++ b/easy/242 Valid Anagram/solution.py @@ -0,0 +1,13 @@ +class Solution: + def isAnagram(self, s: str, t: str) -> bool: + if len(s) != len(t): + return False + + s_dict = {} + for c in s: + s_dict[c] = s_dict.get(c, 0) + 1 + for c in t: + s_dict[c] = s_dict.get(c, 0) - 1 + if s_dict[c] < 0: + return False + return True \ No newline at end of file