242. Valid Anagram

242. Valid Anagram

[Medium] “Given two strings s and t , write a function to determine if t is an anagram of s."

Link to Leetcode

Note: old solution, should review (TODO:)

Python3:

import string

class Solution:
    def isAnagram(self, s: str, t: str) -> bool:
        if len(s) != len(t):
            return False
        else:
            for letter in string.ascii_lowercase:
                if s.count(letter) != t.count(letter):
                    return False
            return True

Python3 (alternative solution #1 - lazy):

class Solution:
    def isAnagram(self, s: str, t: str) -> bool:
        return sorted(s) == sorted(t)