- bool isAnagram(char* s, char* t) {
- int nlen = strlen(s);
- if( nlen != strlen(t) )
- return false;
- if( s == NULL && t== NULL )
- return true;
- int nums[26] = {0};
- int nindex = 0;
- while( nindex<nlen )
- {
- nums[s[nindex]-'a']++;
- nums[t[nindex]-'a']--;
- ++nindex;
- }
- int nindex1 = 0;
- while( nindex1<26 )
- {
- if( nums[nindex1] != 0)
- return false;
- ++nindex1;
- }
- return true;
- }
- //该片段来自于http://www.codesnippet.cn/detail/2208201715235.html
来源: http://www.codesnippet.cn/detail/2208201715235.html