LeetCode 242. Valid Anagram
对俩个字符串各自扫一遍
class Solution { public: bool isAnagram(string s, string t) { int len_s=s.length(); int len_t=t.length(); if(len_s!=len_t){ return false; } int dp[30]; memset(dp,0,sizeof(dp)); for(string::iterator iter = s.begin();iter != s.end();++iter){ dp[*iter-'a']++; } for(string::iterator iter=t.begin();iter!=t.end();iter++){ dp[*iter-'a']--; } for(int i=0;i<26;i++){ if(dp[i]){ return false; } } return true; } };