好贷网好贷款

1.8

发布时间:2016-12-5 4:32:47 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"1.8",主要涉及到1.8方面的内容,对于1.8感兴趣的同学可以参考一下。

Topic: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 is Substring (e.g.“waterbottle” is a rotation of “erbottlewat”) // 知识点:String.indexOf() 返回String对象内第一次出现子字符串的字符位置,如果未找到,返回-1.   // 关键点:判断时,两字符串长度必须相等,且不为空 // 方法1: just check whether s2 is substring of s1+s1 public class CC1_1 { public static boolean isSubstring(String s, String t) { if (s.indexOf(t) >= 0) { return true; } else { return false; } } public static boolean isRotation(String s1, String s2) { /* check that s1 and s2 are equal length and not empty */ if (s1.length() == s2.length() && s1.length() > 0) { /* concatenate s1 and s1 within new buffer */ String s1s1 = s1 + s1; return isSubstring(s1s1, s2); } return false; } public static void main(String[] args) { String[][] pairs = {{"apple", "pleap"}, {"waterbottle", "erbottlewat"}, {"camera", "macera"}}; for (String[] pair : pairs) { String word1 = pair[0]; String word2 = pair[1]; System.out.println(word1 + ", " + word2 + ": " + isRotation(word1, word2)); } } }//结果 apple, pleap: true waterbottle, erbottlewat: true camera, macera: false    

上一篇:mongoDB的数据逻辑结构
下一篇:深入掌握JMS(七):DeliveryMode例子

相关文章

关键词: 1.8

相关评论