LN : leetcode 242 Valid Anagram
lc 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.
analysation##
利用类似于带有26个桶的数组容器存放各个字母在字符串中出现的次数。
solution
bool isAnagram(char* s, char* t) {
int letters[26] = {0}, letters2[26] = {0};
int i, sum = 0, num = 0;
if (strlen(s) != strlen(t))
return false;
for (i = 0; i < strlen(s); i++) {
letters[s[i]-'a']++;
letters2[t[i]-'a']++;
num++;
}
for (i = 0; i < 26; i++) {
if (letters[i] == letters2[i])
sum += letters[i];
}
return (sum == num);
}
LN : leetcode 242 Valid Anagram的更多相关文章
- 22. leetcode 242. Valid Anagram(由颠倒字母顺序而构成的字)
22. 242. Valid Anagram(由颠倒字母顺序而构成的字) Given two strings s and t, write a function to determine if t i ...
- [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: ...
- 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: ...
- 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 ...
- Java [Leetcode 242]Valid Anagram
题目描述: Given two strings s and t, write a function to determine if t is an anagram of s. For example, ...
- 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 = & ...
- Leetcode 242 Valid Anagram pytyhon
题目: Given two strings s and t, write a function to determine if t is an anagram of s. For example,s ...
随机推荐
- poj——1422 Air Raid
Air Raid Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8577 Accepted: 5127 Descript ...
- org.springframework.amqp.AmqpIOException: java.net.UnknownHostException: guest解决
org.springframework.amqp.AmqpIOException: java.net.UnknownHostException: guest 由于在yml文件中配置的时候误将passw ...
- Ubuntu系统备份工具大全(官方整理推荐)
其实官方在系统备份这块已经有Wiki整理和收集各类实用的工具.以下是翻译自官方Wiki的部分文档: 备份工具 wiki文档实用程序 工具 界面 格式类型 Raw/File 支持 远程 增量 差异 自 ...
- 75. Autorelease机制及释放时机
Autorelease机制是iOS开发人员管理对象内存的好伙伴.MRC中.调用[obj autorelease]来延迟内存的释放是一件简单自然的事:ARC下,我们甚至能够全然不知道Autoreleas ...
- Java 中 modifer 'public' is reduntant for interface methods
http://androidren.com/index.php?qa=322&qa_1=java-%E4%B8%AD-modifer-public-is-reduntant-for-inter ...
- Ubuntu虚拟机安装遇到的各种坑
配置 13年Macbook Pro 虚拟机环境 Parallels Desktop Linux 版本 Ubuntu 16.04 1.分辨率问题 进入只有一种分辨率 终端输入 sudo xdiagnos ...
- php(cli模式)执行文件传递参数
php -f index.php hello test 2314 shell命令执行php文件不像http那样通过GET方式传参 同样php文件获取的时候也不能用$_GET方法了 而是通过$argv[ ...
- 第二次PHP面试题
昨天下午翘班去参加了人生中第二次PHP面试.是一家相对第一家更加专业的互联网公司.效果不如第一家理想,笔试题有点难,而且偏高理论,面试时面试官也还不错,一起探讨,可是他的问题我还是很多都不知道,果然是 ...
- YTU 2630: E2 驾驭const
2630: E2 驾驭const 时间限制: 1 Sec 内存限制: 128 MB 提交: 673 解决: 491 题目描述 引入了const关键词,用于指定"常"对象及&qu ...
- JFreeChart基础(1) (转自 JSP开发技术大全)
JFreeChart基础(1) (转自 JSP开发技术大全) JFreeChart是一个Java开源项目,是一款优秀的Java图表生成插件,它提供了在Java Application.Servlet和 ...