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 ...
随机推荐
- mysql你确定掌握的那些sql语句
1.创建表 create table test(uid int not null,create_time timestamp default current_timestamp); 即:没有双引号,单 ...
- 多路转接模型之poll
poll系统调用和select类似.也是在指定时间内轮询一定数量的文件描写叙述符,以測试当中是否有就绪者.poll和select效率差点儿相同,仅仅是其使用接口相对简单些,poll不在局限于1024个 ...
- 在DevExpress GridControl的一列中显示图片
作者:jiankunking 出处:http://blog.csdn.net/jiankunking 近期做项目的时候用到了将GridControl中一列设置为PictureEdit类型,然后通过这一 ...
- Android内存泄露之开篇
先来想这三个问题 内存泄露是怎么回事 内存会泄露的原因 避免内存泄露 1.内存泄露怎么回事 一个程序中,已经不须要使用某个对象,可是由于仍然有引用指向它垃圾回收器就无法回收它,当然该对象占用的内存就无 ...
- JavaSE入门学习5:Java基础语法之keyword,标识符,凝视,常量和变量
一keyword keyword概述:Java语言中有一些具有特殊用途的词被称为keyword.keyword对Java的编译器有着特殊的意义.在程 序中应用时一定要谨慎. keyword特点:组成k ...
- react 项目实战(九)登录与身份认证
SPA的鉴权方式和传统的web应用不同:由于页面的渲染不再依赖服务端,与服务端的交互都通过接口来完成,而REASTful风格的接口提倡无状态(state less),通常不使用cookie和sessi ...
- Android AsyncTask 分析内部实现
sdk3.0前,使用内部的线程池,多线程并发运行.线程池大小等于5,最大达128 sdk3.0后,使用默认的serial线程池.运行完一个线程,再顺序运行下一个线程.sdk3.0<=curren ...
- 《从零開始学Swift》学习笔记(Day67)——Cocoa Touch设计模式及应用之MVC模式
原创文章,欢迎转载.转载请注明:关东升的博客 MVC(Model-View-Controller,模型-视图-控制器)模式是相当古老的设计模式之中的一个,它最早出如今Smalltalk语言中. 如 ...
- mac 终端经常使用命令(三)
基本命令 1.列出文件 ls 參数 文件夹名 例: 看看驱动文件夹下有什么:ls /System/Library/Extensions 參数 -w 显示中文,-l 具体信息. -a 包含 ...
- 【Struts2五】ValueStack以及ognl表达式二(经常使用标签)
Ognl经常使用标签: 1.s:debug 假设把该标签放入到s:iterator中能够看到当前正在迭代的元素的状态 2.s:property 1.输出 ...