-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringRotation.java
More file actions
26 lines (24 loc) · 829 Bytes
/
stringRotation.java
File metadata and controls
26 lines (24 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// https://www.geeksforgeeks.org/problems/check-if-strings-are-rotations-of-each-other-or-not-1587115620/1
import java.util.*;
public class stringRotation {
public static boolean areRotations(String s1, String s2 )
{
// Your code here
// if lengths not equal, return false
// concat s1+s1
// does it contain s2?
if (s1.length() != s2.length()) {
return false;
}
String tempS1 = s1+s1;
System.out.println("10tempS1: " + tempS1);
return tempS1.contains(s2);
}
public static void main(String[] args) {
// String s1 = "geeksforgeeks";
// String s2 = "forgeeksgeeks";
String s1 = "mightandmagic";
String s2 = "andmagicmigth";
System.out.println("Output1: " +areRotations(s1,s2));
}
}