Skip to content

Instantly share code, notes, and snippets.

@dfdemar
Last active December 19, 2015 18:49
Show Gist options
  • Save dfdemar/6001955 to your computer and use it in GitHub Desktop.
Save dfdemar/6001955 to your computer and use it in GitHub Desktop.
Palindrome detector
using System;
public class Test
{
public static void Main()
{
Console.WriteLine(IsPalindrome("amanaplanacanalpanama"));
}
public static bool IsPalindrome(string word)
{
bool isPalindrome = true;
int left = 0;
int right = word.Length - 1;
while (left < right)
{
if (word[left] != word[right])
{
isPalindrome = false;
break;
}
left++;
right--;
}
return isPalindrome;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment