Last active
December 19, 2015 18:49
-
-
Save dfdemar/6001955 to your computer and use it in GitHub Desktop.
Palindrome detector
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
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