Skip to content

Instantly share code, notes, and snippets.

@lomholdt
Last active October 5, 2020 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lomholdt/2d95518e7b6f148188d2d9a045133d6e to your computer and use it in GitHub Desktop.
Save lomholdt/2d95518e7b6f148188d2d9a045133d6e to your computer and use it in GitHub Desktop.
Recursive IsPalindrome implementation
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]);
}
}
}
@lomholdt
Copy link
Author

lomholdt commented Oct 5, 2020

Recursive is palindrome implementation.

Sharplab link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment