Skip to content

Latest commit

 

History

History
25 lines (19 loc) · 682 Bytes

README.md

File metadata and controls

25 lines (19 loc) · 682 Bytes

Valid Anagram

Problem can be found in here!

Solution: Hash Table

def isAnagram(s: str, t: str) -> bool:
    memo = {}
    for token in s:
        try:
            memo[token] += 1
        except KeyError:
            memo[token] = 1

    for token in t:
        try:
            memo[token] -= 1
        except KeyError:
            return False

    return all(count == 0 for count in memo.values())

Time Complexity: O(n), Space Complexity: O(1)