forked from xieqilu/Qilu-leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path61.CheckStringRotation.cs
More file actions
38 lines (32 loc) · 1023 Bytes
/
Copy path61.CheckStringRotation.cs
File metadata and controls
38 lines (32 loc) · 1023 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
27
28
29
30
31
32
33
34
35
36
37
38
//Determine if two strings are right rotation of each other
//OR determine if string1 is a right rotation of string2
//Note: if string1 is a right rotation of string2,
//then string2 must also be a right rotaion of string1
//firstly, if the length of two strings are different,
//Then theay cannot be right rotation of each other
//We can concatenate string1 (double string1) and then
//check if the new string1 contains string2.
using System;
namespace StringRotation
{
public class Finder
{
public static bool CheckRotation(string str1, string str2)
{
if (str1.Length == str2.Length && str1.Length > 0) { //do not forget to check if two strings are both empty
string newStr = string.Concat (str1, str1); //string.concat concatenate two strings
return newStr.Contains (str2);
} else
return false;
}
}
class MainClass
{
public static void Main (string[] args)
{
string str2 = "efgkbcd";
string str3 = "gabcdef";
Console.WriteLine (Finder.CheckRotation (str2,str3));
}
}
}