📅  最后修改于: 2022-03-11 14:49:01.040000             🧑  作者: Mango
//Palindrome = word that reads the same forward as it does backward
public static void Main(string[] args)
{
Console.WriteLine(new Program().Pal("AsdsA"));
}
public bool Pal(string str)
{
int end = str.Length-1;
for (int i = 0, j = end; i < end; i++, j--)
{
char frontLetter = str[i]; //Char.ToLower(str[i]);
char endLetter = str[j]; //Char.ToLower(str[i]);
if (frontLetter != endLetter) return false;
}
return true;
}
---------------------------------------------------------Option1
public bool Pal(string str)
{
char[] rev = str.ToCharArray();
Array.Reverse(rev);
string reversed = new string(rev);
//if ( str.Equals(reversed, StringComparison.OrdinalIgnoreCase) ) return true;
if (str.Equals(reversed)) return true;
else return false;
}
----------------------------------------------------------Option2