I have written an algorithm to find the largest palindrome under a given number, but I am sure my code loses efficiency by creating new arrays in every pass. I am currently learning about efficiency so I have the following question: Can anyone suggest a more efficient (faster) approach and explain why this approach is more efficient?
int number = 0;
int palindrome = 0;
for (int i = 1; i < 999999; i++)
{
number = i;
string s = number.ToString();
char[] charArray = s.ToCharArray();
char[] charArrayReversed = new char[charArray.Length];
Array.Copy(charArray, charArrayReversed, charArray.Length);
Array.Reverse(charArrayReversed);
bool isEqual = Enumerable.SequenceEqual(charArray, charArrayReversed);
if (isEqual)
palindrome = number;
}
Console.Write(palindrome);
Console.ReadLine();