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 ...
随机推荐
- [iOS基础控件 - 6.10.7] UIWindow
A.UIWindow概念 1.继承UIView,是一种特殊的UIView 2.通常一个APP只有一个UIWindow 3.iOS程序启动后,创建的第一个视图就是UIWindow 4.没有UIWindo ...
- properties.load(in); 引出的中文乱码问题
/** * Reads a property list (key and element pairs) from the input byte stream. * The input stream i ...
- SpringMVC(四)
好久没有来谢谢总结性的东西了,一直在赶项目进度,终于忙完了,今天就来说说项目过程中遇到的一些问题: 1.关于在使用@Param的用法,在前面也说过了一点,但是在实际使用中还遇到了一个问题.就是在Map ...
- .Net 代码安全保护产品DNGuard HVM使用
前辈人物写的程序啊! 官方网站:http://www.dnguard.net/index.aspx 官方博客:http://www.cnblogs.com/rick/ (很久没更新了) 原文http: ...
- ADO.NET 快速入门(十二):从 SQL Server 生成 XML 数据
本文演示如何使用2种不同的方法从 SQL Server 生成 XML. 方法1:使用了 SqlCommand 的 ExecuteXmlReader 方法获取 XmlReader,然后使用 Data ...
- iOS 判断只有数字、小数点和减号
#define NUMBERS @"0123456789.-" //数字 #define NUM @"0123456789" //字母 #define ALPH ...
- ssh 设置免password登录
如果: 实现->操作机A机 要以用户"user1"身份.免password登录B机和C机? B机和C机 建立用户 user1 而且能够ssh 登录. A机设置: 1.安装ss ...
- BZOJ 2705: [SDOI2012]Longge的问题 GCD
2705: [SDOI2012]Longge的问题 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnl ...
- C#中使用GUID的笔记
GUID(全局统一标识符)是指在一台机器上生成的数字,它保证对在同一时空中的所有机器都是唯一的.通常平台会提供生成GUID的API.生成算法很有意思,用到了以太网卡地址.纳秒级时间.芯片ID码和许多可 ...
- GLSL 基础量定义
GLSL语法跟C语言非常相似: 1.数据类型: GLSL包含下面几种简单的数据类型 float bool :false or ture int 向量: vec {2,3,4} 长度为2, ...