242. Valid Anagram

problem

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.

Note:
You may assume the string contains only lowercase alphabets.

求两个字符串的字母组成是不是一致

solution

很明显是要用类似字典的方法

Counter 是字典的子类,方向计数

from collections import Counter

class Solution(object):
    def isAnagram(self, s, t):
        """
        :type s: str
        :type t: str
        :rtype: bool
        """
        t = Counter(t)
        s = Counter(s)
        return t == s 
        
posted @ 2016-10-15 15:31  Salmd  阅读(75)  评论(0)    收藏  举报