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. Headfirst设计模式的C++实现——抽象工厂(Abstract Factory)

    Dough.h #ifndef _DOUGH_H #define _DOUGH_H class Dough { }; #endif ThinCrustDough.h #ifndef _THIN_CRU ...

  2. 使用JS实现鼠标滚轮事件

    网站需要实现鼠标滚轮滚一下,页面向下滑向下一个锚点,由于前面有个一样式必须用jQuery1.3.2,而好多滚轮事件都使用了更高版本的jQuery,于是就从网上找了找 <script type=& ...

  3. Spring Cloud Eureka Server 启停状态监控

    目前发现如下的api: 当时没有找到文档 http://localhost:8761/eureka/apps 参考文章:(此文中api带有v2我自己试验不需要v2) http://blog.csdn. ...

  4. 【VB6 学习文档管理系统源码】

    VB6写的一款笔记软件的源码,里面包含有很多窗体控件的使用技巧,比如MSHFlexgrid表格.TreeView的动态加载.Ado的增删改查等. 本软件提供对日常生活.工作中的学习笔记.图文并茂存储以 ...

  5. windows下python 编码问题

    windows下py文件编码: 当print 时遇到unicode 会根据系统编码转换, 而raw_input 中的输出遇到unicode编码是不会的转码的,会报错UnicodeEncodeError ...

  6. [python]类与类中的列表

    最近在用类中的列表时出现一件怪事 实例2中的列表,竟然有实例1中的数据. 查了半天发现是list的append方法的问题. 将全部的list.append(value) 换成 list = list ...

  7. ios 网络字节顺序的转换HTOS

    最近用socket发送data遇到个问题,字节高地位和服务器不匹配,搞了好久才找到解决的方案,主要用到两个函数HTOL HTOS STOH LTOL 故写此博文 什么是字节序 采用维基百科的解释如下: ...

  8. angular分页指令

    目前的多个项目中都用到分页这个功能,为了提高可复用性,我特地分离出来写了个分页的指令.直接贴代码,详情如下: index.html <body id="sBill" ng-c ...

  9. CommonsChunkPlugin的一些总结

    CommonsChunkPlugin 官方文档地址 https://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin new ...

  10. jedis源码阅读

    package redis.clients.jedis; import java.util.ArrayList; import java.util.HashSet; import java.util. ...