标签:ring bsp blog div return lower san contain 记录
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.
//排个序比较一下
//或者用数组记录每个单词出现的次数
//在这我用的是第一种方法,比较快。
1 class Solution { 2 public: 3 bool isAnagram(string s, string t) { 4 if(s.size()!=t.size()) 5 return false; 6 else{ 7 sort(s.begin(),s.end()); 8 sort(t.begin(),t.end()); 9 if(s==t) 10 return true; 11 else 12 return false; 13 } 14 15 16 } 17 };
242. Valid Anagram Add to List
标签:ring bsp blog div return lower san contain 记录
原文地址:http://www.cnblogs.com/hutonm/p/6237913.html