Last active
October 5, 2020 11:31
-
-
Save lomholdt/2d95518e7b6f148188d2d9a045133d6e to your computer and use it in GitHub Desktop.
Recursive IsPalindrome implementation
This file contains hidden or 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
using System; | |
public static class Program | |
{ | |
public static void Main() | |
{ | |
var word = "tenet"; | |
var result = IsPalindrome(word); | |
} | |
public static bool IsPalindrome(string word) | |
{ | |
if (word.Length <= 1) | |
{ | |
return true; | |
} | |
else | |
{ | |
if (word[0] != word[^1]) | |
{ | |
return false; | |
} | |
return IsPalindrome(word[1..^1]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Recursive is palindrome implementation.
Sharplab link