Cracking The Coding Interview 1.8
//Assume you have a method isSubstring which checks if one word is a substring of another.
//Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 using only one call to isSubstring
//( i.e., “waterbottle” is a rotation of “erbottlewat”).
//
// 题意:先写一个判断是否为字串的函数,然后写一个是否是旋转串的函数,调用一次是否为字串函数,来判断是否为旋转串
// 下面的方法来自于http://hawstein.com/posts/ctci-solutions-contents.html
#include <iostream>
#include <string>
using namespace std;
bool isSubstring(string s1, string s2)
{
if(s1.find(s2) != string::npos) return true;
else return false;
} bool isRotation(string s1, string s2)
{
if(s1.length() != s2.length() || s1.length()<=0)
return false;
return isSubstring(s1+s1, s2);
} int main()
{
string s1= "kfuc";
string s2= "fuck";
cout<<isRotation(s1,s2)<<endl;
return 0;
}
Cracking The Coding Interview 1.8的更多相关文章
- 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 ...
随机推荐
- ado.net介绍
System.Data:DataTable,DataSet,DataRow,DataColumn,DataRelation,Constraint System.Data.Common(各种数据访问类的 ...
- 雷林鹏分享:XML 编辑器
XML 编辑器 如果您希望极认真地学习和使用 XML,那么您一定会从一款专业的 XML 编辑器的使用上受益. XML 是基于文本的 XML 是基于文本的标记语言. 关于 XML 的一件很重要的事情是, ...
- java ----> 基础之位运算
package test.ant; import java.util.Arrays; import java.io.UnsupportedEncodingException; public class ...
- 20171026python读取txt写入csv
import csv def get_lines(filepath): with open(filepath) as file_object: lines=set(file_object.readli ...
- 使用Vue建立一个在线商店
git代码:https://github.com/chentianwei411/vue-router-demo.git 使用Vue-CLI3 webpack, ESLInt, Vuex, vue-ro ...
- 网站访问出现 ------ Can not write to cache files, please check directory ./cache/ .
最近在搞微商城时,突然出现了Can not write to cache files, please check directory ./cache/ .这样一个提示, 但最近好像没搞什么大动作,怎么 ...
- Integer to English words leetcode java
问题描述: Convert a non-negative integer to its english words representation. Given input is guaranteed ...
- laravel中连表查询
$skuList = ProductSkuModel::selectRaw('product_skus.id as sku_id, product_skus.code as code, product ...
- 字符串加密解密(Base64)
var Base64 = { // private property _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwx ...
- 第 4 章 用 HTML5 建立超链接
HTML 文件中最重要的应用之一就是超链接.—— 当鼠标单击一些文字.图片或其他网页元素时,浏览器会根据其指示载入一个新的页面或跳转到页面的其他位置. 超链接除了可链接文本外,也可链接各种媒体,如声音 ...