# 解题思路:字典解决其对应关系 20190302 找工作期间
class Solution(object):
def isAnagram(self, s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""
#字母异位词指字母相同,但排列不同的字符串
# dic1=collections.Counter(s)
# dic2=collections.Counter(t)
dic1 = dict()
dic2 = dict()
for i in range(len(s)):
if s[i] not in dic1:
dic1[s[i]] = 1
else:
dic1[s[i]] += 1
for j in range(len(t)):
if t[j] not in dic2:
dic2[t[j]] = 1
else:
dic2[t[j]] += 1
if len(dic1)!=len(dic2):#此种情况直接返回False
return False
for key,value in dic2.items():
if key in dic1 and value==dic1[key]:#key在dic1中并且值相等
continue
else:
return False
return True