MCPcopy Create free account
hub / github.com/careercup/ctci / isRotation

Method isRotation

java/Chapter 1/Question1_8/Question.java:12–21  ·  view source on GitHub ↗
(String s1, String s2)

Source from the content-addressed store, hash-verified

10 }
11
12 public static boolean isRotation(String s1, String s2) {
13 int len = s1.length();
14 /* check that s1 and s2 are equal length and not empty */
15 if (len == s2.length() && len > 0) {
16 /* concatenate s1 and s1 within new buffer */
17 String s1s1 = s1 + s1;
18 return isSubstring(s1s1, s2);
19 }
20 return false;
21 }
22
23 public static void main(String[] args) {
24 String[][] pairs = {{"apple", "pleap"}, {"waterbottle", "erbottlewat"}, {"camera", "macera"}};

Callers 2

mainMethod · 0.95
1_8_Spec.jsFile · 0.80

Calls 2

isSubstringMethod · 0.95
lengthMethod · 0.45

Tested by

no test coverage detected