Skip to content

Instantly share code, notes, and snippets.

@KristofferK
Created January 25, 2018 19:44
Show Gist options
  • Save KristofferK/b1842e7b4574062e1f8b50e659f0f420 to your computer and use it in GitHub Desktop.
Save KristofferK/b1842e7b4574062e1f8b50e659f0f420 to your computer and use it in GitHub Desktop.
Simple palindrome checker
namespace Palindrome
{
class Program
{
static void Main(string[] args)
{
var palindromeChecker = new PalindromeCheckerImpl();
Console.WriteLine(palindromeChecker.IsPalindrome("den laks skal ned"));
Console.WriteLine(palindromeChecker.IsPalindrome("den laks skal ikke ned"));
}
}
public interface IPalindromeChecker
{
bool IsPalindrome(string s);
}
public class PalindromeCheckerImpl : IPalindromeChecker
{
public bool IsPalindrome(string s)
{
if (s.Length < 2) return true;
if (s.First() != s.Last()) return false;
return IsPalindrome(s.Substring(1, s.Length - 2));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment