From bfee35a21c60e062c0033ba4e7e032b86dcadf7c Mon Sep 17 00:00:00 2001 From: TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> Date: Tue, 24 Sep 2024 04:50:56 +0900 Subject: Init --- 1_array_hashing/valid_anagram.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to '1_array_hashing/valid_anagram.py') diff --git a/1_array_hashing/valid_anagram.py b/1_array_hashing/valid_anagram.py index 3305088..57f993e 100644 --- a/1_array_hashing/valid_anagram.py +++ b/1_array_hashing/valid_anagram.py @@ -21,23 +21,31 @@ Input: s = "jar", t = "jam" Output: false +Example 3: + +Input: s = "asneaxl", t = "jinyedp" + +Output: false + Constraints: - s and t consist of lowercase English letters. """ +from typing import Dict + class Solution: def hashmap(self, s: str, t: str) -> bool: if len(s) != len(t): return False - countS: dict = {} - countT: dict = {} + cs: Dict = {} + ct: Dict = {} - for i, si in enumerate(s): - countS[si] = 1 + countS.get(si, 0) - countT[t[i]] = 1 + countT.get(t[i], 0) - return countS == countT + for i, n in enumerate(s): + cs[n] = 1 + cs.get(n, 0) + ct[t[i]] = 1 + ct.get(t[i], 0) + return cs == ct caseS1 = "racecar" -- cgit v1.2.3