Created
January 25, 2018 19:44
-
-
Save KristofferK/b1842e7b4574062e1f8b50e659f0f420 to your computer and use it in GitHub Desktop.
Simple palindrome checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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