zoukankan      html  css  js  c++  java
  • 242 Valid Anagram

    /*
    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
    ", isAnagram(s, t));
        return 0;
    }
    
    
  • 相关阅读:
    curl continue
    actor
    nginx
    jmx additional port
    diff
    lsof
    zk reconnect
    Python:Python基础(一)
    Python:初识Python(二)
    Python:初识Python(一)
  • 原文地址:https://www.cnblogs.com/xzpin/p/11833987.html
Copyright © 2011-2022 走看看