use isSubstring to check if one word is a rotation of another.
1: /// <summary>
2: /// Assume you have a method isSubstring which checks if one word is a substring of another.
3: /// Given two strings, s1 and s2,
4: /// write code to check if s2 is a rotation of s1 using only one call to
5: /// isSubstring (i.e., “waterbottle” is a rotation of “erbottlewat”).
6: /// </summary>
7: class Program
8: {
9: static void Main(string[] args)
10: {
11: string s1 = "waterbottle";
12: string s2 = "erbottlewat";
13: Program p = new Program();
14: bool r = p.IsARotation(s1, s2);
15: }
16:
17: public bool IsARotation(string s1, string s2)
18: {
19: if (string.IsNullOrEmpty(s1) || string.IsNullOrEmpty(s2))
20: {
21: throw new ArgumentNullException("please do not input empty or null string");
22: }
23:
24: if (s1.Length != s2.Length)
25: {
26: return false;
27: }
28:
29: string ns = s1 + s1;
30:
31: return ns.Contains(s2);
32: }
33: }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
use isSubstring to check if one word is a rotation of another.的更多相关文章
- 【LeetCode OJ】Word Ladder I
Problem Link: http://oj.leetcode.com/problems/word-ladder/ Two typical techniques are inspected in t ...
- LeetCode题解:(139) Word Break
题目说明 Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, dete ...
- [LeetCode] 288.Unique Word Abbreviation 独特的单词缩写
An abbreviation of a word follows the form <first letter><number><last letter>. Be ...
- 11-10 CC150第一章
题目: 1.1 Implement an algorithm to determine if a string has all unique characters. What if you can n ...
- [CareerCup] 1.8 String Rotation 字符串的旋转
1.8 Assume you have a method isSubstring which checks if one word is a substring of another. Given t ...
- Cracking the coding interview--Q1.8
原文: Assume you have a method isSubstring which checks if one word is a substring of another. Given t ...
- CCI_chapter 1
1.1Implement an algorithm to determine if a string has all unique characters What if you can not us ...
- Cracking the coding interview--问题与解答
http://www.hawstein.com/posts/ctci-solutions-contents.html 作者:Hawstein出处:http://hawstein.com/posts/c ...
- CareerCup它1.8 串移包括问题
[称号] 原文: 1.8 Assume you have a method isSubstring which checks if one word is a substring of another ...
随机推荐
- 九度OJ 1108 堆栈的使用
题目地址:http://ac.jobdu.com/problem.php?pid=1108 题目描述: 堆栈是一种基本的数据结构.堆栈具有两种基本操作方式,push 和 pop.Push一个值会将其压 ...
- C#使用Json
AJAX传递复杂数据如果自己进行格式定义的话会经历组装.解析的过程,因此AJAX中有一个事实上的数据传输标准JSon. Json将复杂对象序列化为一个字符串,在浏览器端再将字符串反序列化为JavaSc ...
- PHP问题
/usr/bin/ld: cannot find -lltdlcollect2: ld returned 1 exit statusmake: *** [libphp5.la] 错误 1 缺少libt ...
- H5小内容(二)
音视频处理 视频处理 基本内容 使用Flash技术处理HTML页面中的视频内容 包含音频.动画.网页游戏等 特点 浏览器原生不支持(IE浏览器要求安装A ...
- Spring MVC框架理解
原文链接:ITeye SpringMVC深度探险专栏 基本要素 1. 指定SpringMVC的入口程序(在web.xml中) <!-- Processes application request ...
- js 的基础知识变量
什么是变量? 变是一个存储和释放我的数据! 我们用var关键字来声名变量,声名多个变量时用逗号来隔开 在变量没有赋值之前,显示是一个未定义的变量! <script> var a; var ...
- 常用webservice接口地址
天气预报Web服务,数据来源于中国气象局Endpoint :http://www.webxml.com.cn/WebServices/WeatherWebService.asmxDisco ...
- logger.debug,logger.info,logger.warn,logger.error,logger.fatal的区别
logger.debug,logger.info,logger.warn,logger.error,logger.fatal的区别 logger.debug,logger.info,logger.wa ...
- MySQL partition分区I
http://blog.csdn.net/binger819623/article/details/5280267 一. 分区的概念二. 为什么使用分区?(优点)三. ...
- Mysql table ful
http://ourmysql.com/archives/1327 http://blog.csdn.net/kevon_sun/article/details/7967728 http://my.o ...