首页 > 其他 > 详细

LeetCode 242 Valid Anagram

时间:2015-11-14 11:10:11      阅读:238      评论:0      收藏:0      [点我收藏+]

LeetCode 242 Valid Anagram

 

由于都是小写字母,可以建立一个长度为26的数组来记录每个字母出现的次数。C语言实现如下:

bool isAnagram(char* s, char* t) {
    if(strlen(s)!=strlen(t))
        return 0;
    int count[26] = {0};
    char c;
    while ((c=*s++)!=\0)
        count[c-a]++;
    while ((c=*t++)!=\0)
        count[c-a]--;
    for (int i=0; i<26 ;++i)
        if (count[i]!=0)
            return 0;
    return 1;
}

 

LeetCode 242 Valid Anagram

原文:http://www.cnblogs.com/walker-lee/p/4963960.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!