requirements

Given two strings s and t, write a function to determine whether t is an alphabetic allotopic of S.

Note: if each character in S and T occurs the same number of times, s and T are said to be alphabetic allographs.

Example 1:

Input: s = "anagram", t = "nagaram" Output: trueCopy the code

Example 2:

Input: s = "rat", t = "car" output: falseCopy the code

The core code

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

Another solution

class Solution:
    def isAnagram(self, s: str, t: str) - >bool:
        from collections import Counter
        return Counter(s) == Counter(t)
Copy the code

Third solution

class Solution:
    def isAnagram(self, s: str, t: str) - >bool:
        hashmaps,hashmapt = dict(),dict(a)for char in s:
            hashmaps[char] = hashmaps.get(char,0) + 1

        for char in t:
            hashmapt[char] = hashmapt.get(char,0) + 1
        return hashmaps == hashmapt
Copy the code

The first solution is to return the sorted list of two strings and determine whether they are equal. The second solution: we use Counter to count the number of characters in the dictionary is the same; Third solution: Use the dictionary in the same way as in the second method, but we use the loop to build the dictionary ourselves