给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的字母异位词
若 s 和 t 中每个字符出现的次数都相同,则称 s 和 t 互为字母异位词
输入:s = "anagram" t = "nagram" 输出:False
输入:s = "anagram" t = "anagram" 输出:True
def isAnagram(s1, s2): return Counter(s1)==Counter(s2) def isAnagram(s1, s2): return sorted(s1)==sorted(s2) def isAnagram(s, t): s_c, t_c = {}, {} for k in s: if k not in s_c.keys(): s_c[k] = 1 else: s_c[k] += 1 for kk in t: if kk not in t_c.keys(): t_c[kk] = 1 else: t_c[kk] += 1 return s_c==t_c
标签:return,kk,异位,s1,s2,isAnagram From: https://www.cnblogs.com/Yanss/p/16787978.html