LeetCode 242

时间:2023-03-08 16:30:43
LeetCode 242

Valid Anagram

Given two strings s and t, write a function to determine if t is an anagram of s.

For example,
s = "anagram", t = "nagaram", return true.
s = "rat", t = "car", return false.

Note:
You may assume the string contains only lowercase alphabets.

Follow up:
What if the inputs contain unicode characters? How would you adapt your solution to such case?

 /*************************************************************************
> File Name: LeetCode242.c
> Author: Juntaran
> Mail: Jacinthmail@gmail.com
> Created Time: 2016年05月10日 星期二 03时49分39秒
************************************************************************/ /************************************************************************* Valid Anagram Given two strings s and t, write a function to determine if t is an anagram of s. For example,
s = "anagram", t = "nagaram", return true.
s = "rat", t = "car", return false. Note:
You may assume the string contains only lowercase alphabets. Follow up:
What if the inputs contain unicode characters? How would you adapt your solution to such case? ************************************************************************/ #include "stdio.h" int isAnagram(char* s, char* t)
{
int ret; if (strlen(s) != strlen(t))
{
ret = ;
} int i;
int flag[] = {}; for ( i=; i<strlen(s); i++ )
{
flag[s[i] - 'a']++;
printf("%d ",s[i] - 'a');
printf("%d\n",flag[s[i] - 'a']); flag[t[i] - 'a']--;
printf("%d ",t[i] - 'a');
printf("%d\n",flag[t[i] - 'a']);
} for( i=; i<; i++ )
{
if( flag[i] != )
{
ret = ;
}
printf("%d ",flag[i]);
}
ret = ;
printf("\n%d\n",ret); return ret;
} int main()
{
char* s = "nl";
char* t = "cx"; int result = isAnagram(s,t); return ;
}