首页 > 其他 > 详细

1.8 Is Rotation

时间:2014-11-21 15:49:17      阅读:228      评论:0      收藏:0      [点我收藏+]

Assume you have a method isSubstring which checks if one word is a
substring of another. Given two strings, s1 and s2, write code to check if s2 is
a rotation of s1 using only one call to isSubstring (e.g.,"waterbottle"is a rotation
of "erbottlewat").

1 public static boolean isRotation(String s1, String s2) {
2     if(s1 == null || s2 == null)    return false;
3     if(s1.length() != s2.length())    return false;
4 
5     String s3 = s1 + s1;
6     return isSubstring(s3, s2);
7 }

 

1.8 Is Rotation

原文:http://www.cnblogs.com/superbo/p/4112790.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!