Skip to content

Commit a4cade8

Browse files
Added few comments
1 parent fc2ce20 commit a4cade8

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Strings/check_if_strings_are_rotation_of_eachother.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ A Program to check if strings are rotations of each other or not.
66

77
SOLUTION (in C++):
88

9+
//Suppose there are two strings s1 = "devincept" and s2 = "vinceptde",
910

10-
Suppose there are two strings s1 = "devincept" and s2 = "vinceptde",
11+
//to check if s2 is rotation of s1, what we can do is, add s1 to itself
1112

12-
to check if s2 is rotation of s1, what we can do is string result = s1 + s1
13+
// Assign it to another string s3 = s1 + s1
14+
15+
//If s2 is a substring of s1, it is rotation of s1.
1316

14-
and see if s2 is a substring of s1.
1517

1618

1719
#include<bits/stdc++.h>
@@ -25,7 +27,7 @@ int main()
2527
cin>>s1;
2628
cin>>s2;
2729
s3 = s1 + s1;
28-
if(s3.find(s2) != -1 && s1 != s2)
30+
if(s3.find(s2) != -1 && s1 != s2)//if s2 is not a substringof s1 then find returns -1
2931
{
3032
cout<<s2<<" is rotation of "<<s1;
3133
}

0 commit comments

Comments
 (0)