242. Valid Anagram

xiaoxiao2021-02-28  102

Given two strings s and t, write a function to determine if t is an anagram of s.

For example, s = "anagram", t = "nagaram", return true.

s = "rat", t = "car", return false.

class Solution(object):     def isAnagram(self, s, t):         """         :type s: str         :type t: str         :rtype: bool         """                  if list(s) and list(t) and len(list(s))==len(list(t)) and collections.Counter(list(s))==collections.Counter(list(t)):             return set(list(t)).issubset(set(list(s)))         elif not list(s) and not list(t):return True         else:return False                           #  return sorted(s) == sorted(t)

转载请注明原文地址: https://www.6miu.com/read-51789.html

最新回复(0)