From e985a8b5de4b4b0a1a7a8cd58886ff077052b975 Mon Sep 17 00:00:00 2001 From: Rodolfo P A <6721075+rodoufu@users.noreply.github.com> Date: Tue, 7 Jul 2026 10:34:54 -0300 Subject: [PATCH] Create valid-anagram.py --- leetCode/array/valid-anagram.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 leetCode/array/valid-anagram.py diff --git a/leetCode/array/valid-anagram.py b/leetCode/array/valid-anagram.py new file mode 100644 index 0000000..d95a28a --- /dev/null +++ b/leetCode/array/valid-anagram.py @@ -0,0 +1,17 @@ +# https://leetcode.com/problems/valid-anagram/ +class Solution: + def isAnagram(self, s: str, t: str) -> bool: + if len(s) != len(t): + return False + + count_leters_s = {} + count_leters_t = {} + + for l in s: + count_leters_s[l] = count_leters_s.get(l, 0) + 1 + + for l in t: + count_leters_t[l] = count_leters_t.get(l, 0) + 1 + + return count_leters_s == count_leters_t +