MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / Main

Class Main

StringRotations.java:1–26  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1public class Main
2{
3 public static void main(String[] args) {
4 System.out.println(isRotation("ABCD","ACBD"));
5 }
6 public static boolean isRotation(String s1, String s2)
7 {
8 int n1=s1.length();
9 int n2=s2.length();
10 n1+=n1;
11 s1=s1+s1;
12 int i=0,j=0;
13 while(i<n1 && j<n2)
14 {
15 if(i<n1 && j<n2 && s1.charAt(i)==s2.charAt(j)) j++;
16 else
17 {
18 if(j>0) i-=j;
19 j=0;
20 }
21 i++;
22 if(j==n2) return true;
23 }
24 return false;
25 }
26}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected