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.的更多相关文章

  1. 【LeetCode OJ】Word Ladder I

    Problem Link: http://oj.leetcode.com/problems/word-ladder/ Two typical techniques are inspected in t ...

  2. LeetCode题解:(139) Word Break

    题目说明 Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, dete ...

  3. [LeetCode] 288.Unique Word Abbreviation 独特的单词缩写

    An abbreviation of a word follows the form <first letter><number><last letter>. Be ...

  4. 11-10 CC150第一章

    题目: 1.1 Implement an algorithm to determine if a string has all unique characters. What if you can n ...

  5. [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 ...

  6. Cracking the coding interview--Q1.8

    原文: Assume you have a method isSubstring which checks if one word is a substring of another. Given t ...

  7. CCI_chapter 1

    1.1Implement an algorithm to determine if a string has all unique characters What if  you can not us ...

  8. Cracking the coding interview--问题与解答

    http://www.hawstein.com/posts/ctci-solutions-contents.html 作者:Hawstein出处:http://hawstein.com/posts/c ...

  9. CareerCup它1.8 串移包括问题

    [称号] 原文: 1.8 Assume you have a method isSubstring which checks if one word is a substring of another ...

随机推荐

  1. Spring框架的初步学习

    (1) IOC 控制反转 所谓的控制反转就是应用本身不负责依赖对象的创建和维护,依赖对象的创建及维护是由 外部容器负责的(spring是外部容器之一).这样控制权就由应用转移到了外部容器,控制权 的转 ...

  2. Ubuntu下gcc及g++环境配置

    直接在命令行中输入以下命令即可. sudo apt-get install build-essential 安装完成后输入 gcc 和 g++ 进行确认.

  3. 从追MM谈Java的23种设计模式

    从追MM谈Java的23种设计模式 1.FACTORY—追MM少不了请吃饭了,麦当劳的鸡翅和肯德基的鸡翅都是MM爱吃的东西,虽然口味有所不同,但不管你带MM去麦当劳或肯 德基,只管向服务员说“来四个鸡 ...

  4. bm25

    BM25算法,通常用来作搜索相关性平分.一句话概况其主要思想:对Query进行语素解析,生成语素qi:然后,对于每个搜索结果D,计算每个语素qi与D的相关性得分,最后,将qi相对于D的相关性得分进行加 ...

  5. jquery完善的处理机制

    使用jQuery选择器不仅比使用传统的getElementById()和getElementsByTagName()函数简洁得多,而且还能避免某些错误.请看下面例子: <script> d ...

  6. 你需要了解的z-index世界

    本文摘自:飘零雾雨的博客 z-index的重要性 在我看来,z-index 给了我们日常工作中以极大的帮助,我们用它来定义元素的层叠级别(stack level).受益于它,你能做Popup, Dro ...

  7. Java RMI(远程方法调用)开发

    参考 https://docs.oracle.com/javase/7/docs/platform/rmi/spec/rmi-arch2.html http://www.cnblogs.com/wxi ...

  8. 由css属性:vertial-align想到的。。

    我的笔记本:型号 acer4750G-2412g50mnkk 分辨率:1333*768,点距:0.25933mm; 12px下的font-size: 默认line-height减去font-size: ...

  9. Aspose.Cells 导入导出EXCEL(转)

    Aspose.Cells 导入导出EXCEL      修改样式        Workbook workbook = new Workbook(); //工作簿          Worksheet ...

  10. eclipse打开文件目录

    在MyEclipse开发中常用到其中一个"Open In Explorer"的小插件,可以直接进入Windows资源管理器中打开选中文件所在的目录,在使用eclipse开发时也很需 ...