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 ;
}

LeetCode 242的更多相关文章

  1. C#版[击败99.69%的提交] - Leetcode 242. 有效的同构异形词 - 题解

    C#版 - Leetcode 242. 有效的同构异形词 - 题解 Leetcode 242.Valid Anagram 在线提交: https://leetcode.com/problems/val ...

  2. 前端与算法 leetcode 242. 有效的字母异位词

    目录 # 前端与算法 leetcode 242. 有效的字母异位词 题目描述 概要 提示 解析 解法一:哈希表 解法二:数组判断字符出现次数 解法三:转换字符串 算法 传入测试用例的运行结果 执行结果 ...

  3. LeetCode 242. 有效的字母异位词(Valid Anagram)

    242. 有效的字母异位词 LeetCode242. Valid Anagram 题目描述 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的一个字母异位词. 示例 1: 输入: s ...

  4. 22. leetcode 242. Valid Anagram(由颠倒字母顺序而构成的字)

    22. 242. Valid Anagram(由颠倒字母顺序而构成的字) Given two strings s and t, write a function to determine if t i ...

  5. LN : leetcode 242 Valid Anagram

    lc 242 Valid Anagram 242 Valid Anagram Given two strings s and t, write a function to determine if t ...

  6. 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 = &q ...

  7. [LeetCode] 242. Valid Anagram 验证变位词

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

  8. Java实现 LeetCode 242 有效的字母异位词

    242. 有效的字母异位词 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的字母异位词. 示例 1: 输入: s = "anagram", t = " ...

  9. LeetCode 242 Valid Anagram

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

  10. (easy)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 = &q ...

随机推荐

  1. javascript 获取HTML DOM父、子、临近节点

    在Web应用程序特别是Web2.0程序开发中,经常要获取页面中某个元素,然后更新该元素的样式.内容等.如何获取要更新的元素,是首先要解决的问题.令人欣慰的是,使用JavaScript获取节点的方法有很 ...

  2. UVaLive 7372 Excellence (水题,贪心)

    题意:给定 n 个数,要求把其中两个分成一组,然后加和,问所有的都分好,最小数是几. 析:贪心策略,最大和是小的相加,就是最优的. 代码如下: #pragma comment(linker, &quo ...

  3. 被mysql中的wait_timeout坑了

    今天被mysql里的wait_timeout坑了         网上能搜到很多关于mysql中的wait_timeout相关的文章,但是大多数只是说明了他的作用,而且都说这个参数要配合那个inter ...

  4. Epplus 使用的简单介绍

    操作Excel的主要有以下类库: MyXls(http://sourceforge.net/projects/myxls/) Koogra(http://sourceforge.net/project ...

  5. How to Be Good at Mathematics

    How to Be Good at Mathematics Community Q&A Sometimes, the hardest subject for some people is ma ...

  6. 蓝桥杯--Quadratic Equation

    蓝桥杯--Quadratic Equation 问题描述 求解方程ax2+bx+c=0的根.要求a, b, c由用户输入,并且可以为任意实数. 输入格式:输入只有一行,包括三个系数,之间用空格格开. ...

  7. cocos2d-x 多线程以及线程同步

    转自:http://blog.csdn.net/zhy_cheng/article/details/9116479 cocos2d-x引擎在内部实现了一个庞大的主循环,每帧之间更新界面,如果耗时的操作 ...

  8. 正则表达式(Regular Expression)

    匹配中文字符的正则表达式: [\u4e00-\u9fa5] 评注:匹配中文还真是个头疼的事,有了这个表达式就好办了 匹配双字节字符(包括汉字在内):[^\x00-\xff] 评注:可以用来计算字符串的 ...

  9. 如何给你的VS2010添加创建文件后的头注释

    修改VS自带的模板 1) 类文件 D:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplatesCache\ ...

  10. Codeforces Round #334 (Div. 2) D. Moodular Arithmetic 环的个数

    D. Moodular Arithmetic Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/60 ...