Given two strings s and t , write a function to determine if t is an anagram of s.
Example 1:
Note:
You may assume the string contains only lowercase alphabets.
Follow up:
What if the inputs contain unicode characters? How would you adapt your solution to such case?
class Solution(object): def isAnagram(self, s, t): if not s and not t: # reminder: always check the base case(s) return True if len(s) != len(t): # reminder: always check the base case(s) return False for char in set(s): if s.count(char) != t.count(char): # count has to run on O(n) time, therefore, return False # I am not sure why this code runs faster? return True # Less passes?
以上