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 ;
}
LeetCode 242的更多相关文章
- C#版[击败99.69%的提交] - Leetcode 242. 有效的同构异形词 - 题解
C#版 - Leetcode 242. 有效的同构异形词 - 题解 Leetcode 242.Valid Anagram 在线提交: https://leetcode.com/problems/val ...
- 前端与算法 leetcode 242. 有效的字母异位词
目录 # 前端与算法 leetcode 242. 有效的字母异位词 题目描述 概要 提示 解析 解法一:哈希表 解法二:数组判断字符出现次数 解法三:转换字符串 算法 传入测试用例的运行结果 执行结果 ...
- LeetCode 242. 有效的字母异位词(Valid Anagram)
242. 有效的字母异位词 LeetCode242. Valid Anagram 题目描述 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的一个字母异位词. 示例 1: 输入: s ...
- 22. leetcode 242. Valid Anagram(由颠倒字母顺序而构成的字)
22. 242. Valid Anagram(由颠倒字母顺序而构成的字) Given two strings s and t, write a function to determine if t i ...
- 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 ...
- 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 ...
- [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: ...
- Java实现 LeetCode 242 有效的字母异位词
242. 有效的字母异位词 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的字母异位词. 示例 1: 输入: s = "anagram", t = " ...
- 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 ...
- (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 ...
随机推荐
- python中列表,元组,字符串如何互相转换
python中有三个内建函数:列表,元组和字符串,他们之间的互相转换使用三个函数,str(),tuple()和list(),具体示例如下所示: >>> s = "xxxxx ...
- Windows安全模式的妙用
使用计算机的老手一定对windows安全模式不陌生,在删除病毒,卸载顽固软件,或者系统维护时,Windows的安全模式肯定会帮助很大,下面电脑技术就说说Windows安全模式的作用以及用处. wind ...
- exit和_exit的区别
参考 http://www.cnblogs.com/hnrainll/archive/2011/08/17/2142001.html p.p1 { margin: 0.0px 0.0px 0.0px ...
- Python3爬虫学习
学了几天python3,发现目前学到的与爬虫还是关系不大,所以现在准备爬虫和语言同步学习. 2016.8.9晚 先从最简单的开始,爬取指定url的所有内容: #encoding:UTF-8 impor ...
- cocos2d-x CCScrollView
转自:http://www.cnblogs.com/dcxing/archive/2012/12/31/2840217.html ScrollView一般用在游戏的关卡选择这种类似的场景还有帮助这种场 ...
- PostgreSQL建表动作分析
首先,建立表: pgsql=# create table tab10(id integer); CREATE TABLE pgsql::regclass; regclass ---------- ta ...
- hdu 5563 Clarke and five-pointed star 水题
Clarke and five-pointed star Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/show ...
- HDU 4588 Count The Carries 数学
Count The CarriesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
- C/C++学习站点资源
学习论坛: 轩辕软件论坛 中国IT实验室C/C++论坛 编程爱好者论坛 编程中国论坛 进阶站点: 浙江工业 http://acm.zjut.edu.cn 浙江大学 http://acm.zju.edu ...
- Mesos 配置项解析
Mesos 的 配置项 能够通过启动时候传递參数或者配置文件夹下文件的方式给出(推荐方式,一目了然). 分为三种类型:通用项(master 和 slave 都支持).仅仅有 master 支持的,以及 ...