首页 > 其他 > 详细

242 Valid Anagram

时间:2019-11-11 13:19:48      阅读:80      评论:0      收藏:0      [点我收藏+]
/*
Author: Zoro
Date:   2019/11/10
Function:   Valid Anagram
Title:  leetcode 242
anagram.c
think:  桶排序思想
*/
#include <stdio.h>
#include <stdbool.h>
#include <string.h>

bool isAnagram(char *s, char *t) {
    int statS[26] = {0};
    int statT[26] = {0};
    int lenS = strlen(s);
    int lenT = strlen(t);
    int i;
    for (i=0; i<lenS; i++) {
        int index = s[i] - 'a';
        statS[index]++;
    }
    for (i=0; i<lenT; i++) {
        int index = t[i] - 'a';
        statT[index]++;
    }
    for (i=0; i<26; i++) {
        if (statS[i] != statT[i]) {
            return false;
        }
    }
    return true;
}

int main() {
    char* s = "hello";
    char* t = "ehllo";
    printf("%d\n", isAnagram(s, t));
    return 0;
}

242 Valid Anagram

原文:https://www.cnblogs.com/xuzhaoping/p/11833987.html

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