Skip to content

Commit d46e44e

Browse files
committed
String rotation in Java.
1 parent 88adb71 commit d46e44e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

solutions/java/StringRotation.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class StringRotation {
2+
3+
public static void main(String[] args) {
4+
// TODO Auto-generated method stub
5+
StringRotation sr = new StringRotation();
6+
System.out.println(sr.isRotation("ABCD", "BCDA"));
7+
}
8+
9+
public boolean isRotation(String one, String two) {
10+
/**
11+
* This code checks if one is a rotation of two The way it works is -
12+
* concatenate the original string with itself, and check if the rotated
13+
* string is contained in it. For example : ABCD is contained in BCDABCDA
14+
*/
15+
return (two + two).contains(one);
16+
}
17+
}

0 commit comments

Comments
 (0)