//Write a method to decide if two strings are anagrams or not.
//
// 变位词(anagrams)指的是组成两个单词的字符相同,但位置不同的单词。比如说, abbcd和abcdb就是一对变位词。
//
// 使用一个固定数组大小记录各个字符出现的次数,同1.1
#include <iostream>
using namespace std;
bool isAnagrams(const char *a, const char *b)
{
int asize = strlen(a);
int bsize = strlen(b);
if (asize != bsize)
{
return false;
}
int isAna[26] = {0};
for (int i =0; i <asize; i++)
{
int t = a[i] - 'a';
isAna[t]++;
t = b[i] - 'a';
isAna[t]--;
}
bool isA = true;
for ( int j=0; j <26; j++)
{
if (isAna[j]!=0)
{
isA = false;
}
}
return isA; } int main()
{
char *s1 = "fuckyou";
char *s2 = "youfuck";
cout<<isAnagrams(s1,s2);
return 0;
}

Cracking The Coding Interview 1.4的更多相关文章

  1. Cracking the coding interview

    写在开头 最近忙于论文的开题等工作,还有阿里的实习笔试,被虐的还行,说还行是因为自己的水平或者说是自己准备的还没有达到他们所需要人才的水平,所以就想找一本面试的书<Cracking the co ...

  2. Cracking the coding interview 第一章问题及解答

    Cracking the coding interview 第一章问题及解答 不管是不是要挪地方,面试题具有很好的联系代码总用,参加新工作的半年里,做的大多是探索性的工作,反而代码写得少了,不高兴,最 ...

  3. Cracking the Coding Interview(Trees and Graphs)

    Cracking the Coding Interview(Trees and Graphs) 树和图的训练平时相对很少,还是要加强训练一些树和图的基础算法.自己对树节点的设计应该不是很合理,多多少少 ...

  4. Cracking the Coding Interview(Stacks and Queues)

    Cracking the Coding Interview(Stacks and Queues) 1.Describe how you could use a single array to impl ...

  5. 《Cracking the Coding Interview》读书笔记

    <Cracking the Coding Interview>是适合硅谷技术面试的一本面试指南,因为题目分类清晰,风格比较靠谱,所以广受推崇. 以下是我的读书笔记,基本都是每章的课后习题解 ...

  6. Cracking the coding interview目录及资料收集

    前言 <Cracking the coding interview>是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book. 第六版 ...

  7. 《Cracking the Coding Interview》——第13章:C和C++——题目6

    2014-04-25 20:07 题目:为什么基类的析构函数必须声明为虚函数? 解法:不是必须,而是应该,这是种规范.对于基类中执行的一些动态资源分配,如果基类的析构函数不是虚函数,那么 派生类的析构 ...

  8. 《Cracking the Coding Interview》——第5章:位操作——题目7

    2014-03-19 06:27 题目:有一个数组里包含了0~n中除了某个整数m之外的所有整数,你要设法找出这个m.限制条件为每次你只能用O(1)的时间访问第i个元素的第j位二进制位. 解法:0~n的 ...

  9. 二刷Cracking the Coding Interview(CC150第五版)

    第18章---高度难题 1,-------另类加法.实现加法. 另类加法 参与人数:327时间限制:3秒空间限制:32768K 算法知识视频讲解 题目描述 请编写一个函数,将两个数字相加.不得使用+或 ...

  10. 《Cracking the Coding Interview 》之 二叉树的创建 与 遍历(非递归+递归version)

    #include <iostream> #include <cstdio> #include <vector> #include <stack> #de ...

随机推荐

  1. GenomicConsensus (quiver, arrow)使用方法 | 序列 consensus

    https://github.com/PacificBiosciences/GenomicConsensus GenomicConsensus 是pacbio开发的,我个人非常不喜欢pacbio开发的 ...

  2. hdu-2419 Boring Game

    http://acm.hdu.edu.cn/showproblem.php?pid=2419 给一个图,预分配点值.随后有三种操作,F u v查询与u联通部分大于等于v的最小的数,没有则返回0,U u ...

  3. Confluence 6 创建小组的公众空间

    现在是我们可以开始创建公众空间的时候了,全世界都希望知道这个项目和勇敢的探险活动. 在这个步骤中,我们将会创建一个项目小组的空间,并且将这个空间公布给全世界.这个表示的是你将会让你的 Confluen ...

  4. CF1010F Tree

    真·毒瘤题 这个题面写错了一句话.要求的是每个节点的石子树>=它的两个儿子石子数的和. 首先考虑怎么算石子分配的方案. 如果对这棵树每个节点的石子数都和儿子差分一下的话,可以唯一对应一颗每个点都 ...

  5. Linux 文本编辑器 vim

    第五讲 文本编辑器 vim

  6. Integer to English words leetcode java

    问题描述: Convert a non-negative integer to its english words representation. Given input is guaranteed ...

  7. 『TensorFlow』高级高维切片gather_nd

    gather用于高级切片,有关官方文档的介绍,关于维度的说明很是费解,示例也不太直观,这里给出我的解读,示例见下面,     indices = [[0, 0], [1, 1]]    params ...

  8. button disable and enable

    1. disable <button id="buttonId" disabled>......</button> $("#buttonId&qu ...

  9. flex布局文本过长不显示省略号

    https://www.cnblogs.com/tgxh/p/6916930.html 解决方法: 给flex子元素添加css: white-space: nowrap; text-overflow: ...

  10. dir()函数