forked from MakeContributions/DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpalindrome.cs
28 lines (26 loc) · 848 Bytes
/
palindrome.cs
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
using System;
using System.Linq;
using System.Text.RegularExpressions;
namespace Algorithms.Strings
{
public class Palindrome
{
public static void Main()
{
bool result = false;
result = IsPalindrome("abba");
Console.WriteLine(result);
result = IsPalindrome("abbccbbA");
Console.WriteLine(result);
result = IsPalindrome("Mr. Owl ate my metal worm");
Console.WriteLine(result);
}
public static bool IsPalindrome(string source)
{
source = source.ToLower();
source = Regex.Replace(source, @"[^0-9A-Za-z]", "");
string reverse = new string(Enumerable.Range(1, source.Length).Select(i => source[source.Length - i]).ToArray());
return reverse == source;
}
}
}