forked from TheAlgorithms/C-Sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
palindrome.cs
30 lines (27 loc) · 854 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
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)));
// Typify string to lower and remove white spaces.
private static string TypifyString(string word) =>
Regex.Replace(word.ToLowerInvariant(), @"\s+", string.Empty);
private static string ReverseString(string s)
{
var arr = s.ToCharArray();
Array.Reverse(arr);
return new string(arr);
}
}
}