Valid Anagram
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.
对字符排序,如果排序后相等则true。
1 class Solution { 2 public: 3 bool isAnagram(string s, string t) { 4 sort(s.begin(),s.end()); 5 sort(t.begin(),t.end()); 6 if(s==t) return true; 7 else return false; 8 } 9 };