-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheck_string_rotation.java
57 lines (49 loc) · 1.2 KB
/
check_string_rotation.java
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//Method1 :-
package dynamic_programming;
//import java.lang.*;
public class check_string_rotation {
public static void main(String[] args) {
String a="waterbottle";
String b="erbottlewat";
boolean flag=false;
int i= b.length()-1; // i=5
while(i!=0)
{
if(!((a.contains(b.substring(0,i))) && (a.contains(b.substring(i, b.length())))))
{
i--;
}
else
{
flag=true;
break;
}
}
if(flag)
System.out.println("yes, its a rotation");
else
System.out.println("No, its not a rotation");
//System.out.println(a.substring(1,3));
}
}
//_____________________________________________________________________________________________________________________________
//method 2
import java.util.*;
import java.lang.*;
import java.io.*;
class GFG {
public static void main (String[] args) {
//code
Scanner sc= new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
String str1= sc.next();
String str2= sc.next();
if(str2.concat(str2).contains(str1))
System.out.println(1);
else
System.out.println(0);
}
}
}