forked from TheAlgorithms/C-Sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
palindrome.cs
32 lines (29 loc) · 874 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
29
30
31
32
using System;
using System.Text.RegularExpressions;
namespace Algorithms.Strings
{
/// <summary>
/// TODO.
/// </summary>
public static class Palindrome
{
/// <summary>
/// TODO.
/// </summary>
/// <param name="word">TODO. 2.</param>
/// <returns>TODO. 3.</returns>
public static bool IsStringPalindrome(string word) =>
TypifyString(word).Equals(TypifyString(ReverseString(word)));
private static string TypifyString(string word)
{
// Typify string to lower and remove white spaces.
return Regex.Replace(word.ToLowerInvariant(), @"\s+", string.Empty);
}
private static string ReverseString(string s)
{
var arr = s.ToCharArray();
Array.Reverse(arr);
return new string(arr);
}
}
}