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.
Follow up:
What if the inputs contain unicode characters? How would you adapt your solution to such case?
Solution
- 排序s,t, 看是否相同
1 2 3 4 5 6 7 8 |
|
- Java solution: 利用hash_map存每个字母出现次数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|