Unofficial C Solution to Problem 1.8 in Cracking the Coding Interview (5th Edition)

12 Apr

If string str1 is a rotation of string str2, it must holds two conditions:

  1. The length of str1 equals to the length of str2;
  2. There is at least a set of two string A and B, such that str1=AB and str2=BA. We double str1, and get a new string as ABAB. If str2 is a rotation of str1, str2 must be a substring of this new string.

Leave a Reply

Your email address will not be published. Required fields are marked *

Please put your code into a <pre>YOUR CODE</pre> section. Thanks and Happy Coding!