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. windows平台 culture name 详细列表

    点击打开链接http://msdn.microsoft.com/zh-cn/goglobal/bb896001.aspx LCID Culture Identifier Culture Name Lo ...

  2. Jquery EasyUI中treegrid的中右键菜单和一般按钮同时绑定事件时的怪异事件

    做个项目使用jquery  easyui来做前端,也许是对此不是很熟悉,总是发现一些不可理解的事件. 主要源代码如下: <script type="text/javascript&qu ...

  3. css中 中文字体(font-family)的标准英文名称

    Mac OS的一些: 华文细黑:STHeiti Light [STXihei] 华文黑体:STHeiti 华文楷体:STKaiti 华文宋体:STSong 华文仿宋:STFangsong 儷黑 Pro ...

  4. python入门 第二天笔记

    程序主文件标志if __name__=="__main__": 在程序执行python 1.py 时候 程序1.py __name__ 为 main调用其他文件是,__name__ ...

  5. web2py相关-------------------------------(一)初遇

    在第一次换工作的时候,希望转行 做编程,就面试了很多家,很多人问我 懂不懂html 书写,我非常诚实的告诉他们不会. 当然那时我很天真的认为,只要自己愿意学习这些都不是问题,事实证明人的学习能力是很快 ...

  6. 如何利用C生成.so供Mono调用

    Mono诞生的初衷是为了吸引更多的Windows .Net程序员来加入Linux平台的开发.但在Linux世界中C语言依然是 主流.很多时候一些关键应用(比如大型 笛卡儿 乘积运算.需要调用平台硬件功 ...

  7. java通过jni方式获取硬盘序列号(windows,linux)

    linux系统java通过jni方式获取硬盘序列号 http://blog.csdn.net/starter110/article/details/8186788 使用jni在windows下读取硬盘 ...

  8. Sectong日志分析

    http://tech.uc.cn/?p=2866#comments http://blog.sectong.com/blog/hw_bigdata.html

  9. flume 报File Channel transaction capacity cannot be greater than the capacity of the channel capacity错误

    今天在部署flume集群时,在启动collector服务器没报错,启动agent服务器报错: File Channel transaction capacity cannot be greater t ...

  10. 转:三十二、Java图形化界面设计——布局管理器之CardLayout(卡片布局)

    转:http://blog.csdn.net/liujun13579/article/details/7773945 卡片布局能够让多个组件共享同一个显示空间,共享空间的组件之间的关系就像一叠牌,组件 ...