Check if the string repeats itself any number of times and return true if it does. Otherwise return false
Examples:
abaaba True
ababa False
ababab True
aaaaa True
Solution:
public static bool RepeatedSubstringPattern(string s)
{
int n = s.Length;
StringBuilder sb = new StringBuilder();
for (int i = n / 2; i >= 1; i--)
{
if (n % i == 0)
{
for (int j = 0; j < n / i; j++)
{
sb.Append(s.Substring(0, i));
}
if (sb.ToString().Equals(s)) return true;
sb.Clear();
}
}
return false;
}