Cracking The Coding Interview 1.4
//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的更多相关文章
- Cracking the coding interview
写在开头 最近忙于论文的开题等工作,还有阿里的实习笔试,被虐的还行,说还行是因为自己的水平或者说是自己准备的还没有达到他们所需要人才的水平,所以就想找一本面试的书<Cracking the co ...
- Cracking the coding interview 第一章问题及解答
Cracking the coding interview 第一章问题及解答 不管是不是要挪地方,面试题具有很好的联系代码总用,参加新工作的半年里,做的大多是探索性的工作,反而代码写得少了,不高兴,最 ...
- Cracking the Coding Interview(Trees and Graphs)
Cracking the Coding Interview(Trees and Graphs) 树和图的训练平时相对很少,还是要加强训练一些树和图的基础算法.自己对树节点的设计应该不是很合理,多多少少 ...
- 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 ...
- 《Cracking the Coding Interview》读书笔记
<Cracking the Coding Interview>是适合硅谷技术面试的一本面试指南,因为题目分类清晰,风格比较靠谱,所以广受推崇. 以下是我的读书笔记,基本都是每章的课后习题解 ...
- Cracking the coding interview目录及资料收集
前言 <Cracking the coding interview>是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book. 第六版 ...
- 《Cracking the Coding Interview》——第13章:C和C++——题目6
2014-04-25 20:07 题目:为什么基类的析构函数必须声明为虚函数? 解法:不是必须,而是应该,这是种规范.对于基类中执行的一些动态资源分配,如果基类的析构函数不是虚函数,那么 派生类的析构 ...
- 《Cracking the Coding Interview》——第5章:位操作——题目7
2014-03-19 06:27 题目:有一个数组里包含了0~n中除了某个整数m之外的所有整数,你要设法找出这个m.限制条件为每次你只能用O(1)的时间访问第i个元素的第j位二进制位. 解法:0~n的 ...
- 二刷Cracking the Coding Interview(CC150第五版)
第18章---高度难题 1,-------另类加法.实现加法. 另类加法 参与人数:327时间限制:3秒空间限制:32768K 算法知识视频讲解 题目描述 请编写一个函数,将两个数字相加.不得使用+或 ...
- 《Cracking the Coding Interview 》之 二叉树的创建 与 遍历(非递归+递归version)
#include <iostream> #include <cstdio> #include <vector> #include <stack> #de ...
随机推荐
- 第一个Netty程序
netty就是一个高性能的NIO框架,用于java网络编程.下面说说思路: 服务端: 开启通道.设置网络通信方式.设置端口.设置接收请求的handler.绑定通道.最后关闭 客户端: 开启通道.设置网 ...
- MySql安装成功后无法远程登录
MySql安装成功之后在服务器能够登录,但是在客户端却不能登录.只需要按照如下操作即可 请使用mysql管理工具,如:SQLyog Enterprise 可能是你的帐号不允许从远程登陆,只能在loca ...
- 初探nginx负载均衡配置
只简单说一下upstream的配置,如何进行负载均衡后续还需要多了解 1.另准备一个配置文件命名为nginx_test.conf 为了不污染原有的nginx.conf,提前复制一份配置文件做试验,然后 ...
- GrindEQ Math Utilities 2015破解版 图文安装和序列号补丁激活教程
GrindEQ Math Utilities 2015破解版 图文安装和序列号补丁激活教程 https://www.sdbeta.com/mf/2018/1002/226048.html 软件下载: ...
- 如何在Virtualbox中对Ubuntu系统根分区扩容
转载: 参见博客: https://blog.csdn.net/LEON1741/article/details/56494797 前在Virtualbox中安装了一个Ubun ...
- HTML第十章总结
前言 这一章节讲了以下内容: 两个新的 HTML elelments:它们是 <div>和 <span>,使用这两个 element 可以使得 HTML 有更加 serious ...
- English trip V1 - B 2. May I Help You? 它是多少钱? Teacher:Lamb Key:
In this lesson you will learn to ask for things in shops 这节课您将学习如何在商店中寻找东西 课上内容(Lesson) 你通常去哪里购物? W ...
- English trip M1 - PC1 Are you a Model? 你是模特吗? Teacher:Taylor
In this lesson you will learn to talk about jobs. 课上内容(Lesson) What's your partner name? Her name is ...
- wordpress +window 走起~
一.安装XAMPP 1 百度搜索xampp后下载安装到D盘(安装时按默认勾选安装即可) 2 安装完后,点击Start来启动Apache和MySQL这两个服务 3 如果Apache服务不能启动,多数 ...
- python记录_day018 md5加密
MD5 用法: import hashlib obj = hashlib.md5(加盐) obj.update(明文的bytes) obj.hexdigest() 获取密文 示例: import ha ...