Problem A phrase is a palindrome if, after converting all uppercase letters to lowercase and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers. Given a string s, return true if it is a palindrome, or false otherwise.
Example Input s = A man, a plan, a canal: Panama. Output true. Explanation amanaplanacanalpanama is a palindrome.
Approach The key idea is to ignore all characters that are not letters or digits and compare the remaining characters in lowercase from both ends toward the center. A clean and readable way in C# is to use LINQ to filter and normalize the string, then apply two pointers for comparison. With LINQ, we remove non-alphanumeric characters and convert everything to lowercase. With two pointers, we traverse from the left and right and exit early if we find a difference; if we reach the center without differences, the string is a palindrome.
Code public bool IsPalindrome(string s) { var alphaNum = s.Where(char.IsLetterOrDigit).Select(char.ToLower).ToArray(); int left = 0, right = alphaNum.Length - 1; while (left < right) { if (alphaNum[left] != alphaNum[right]) return false; left++; right--; } return true; }
Notes This method is efficient in clarity and performance for the C# LeetCode 125 Valid Palindrome Easy problem. It avoids unnecessary manipulations and allows exiting as soon as a discrepancy is detected. Using LINQ improves readability by separating the cleaning phase from the two-pointer comparison phase.
About Q2BSTUDIO Q2BSTUDIO is a custom software and application development company specializing in modern technological solutions. We offer custom software, custom applications, and artificial intelligence integration for businesses. Our cybersecurity specialists ensure that solutions are secure by design. We provide AWS and Azure cloud services to deploy and scale applications with high availability. Additionally, we work on business intelligence services and implementations with Power BI to transform data into decisions, and we develop AI agents and AI solutions for companies that automate processes and generate real value. If you are looking for custom software, custom applications, artificial intelligence, cybersecurity, AWS and Azure cloud services, business intelligence services, AI for businesses, AI agents, or Power BI, Q2BSTUDIO can design and implement the right solution for your needs.
Contact Get in touch with our team to explore how we can help you with custom software development, artificial intelligence implementation, cybersecurity improvements, and migrations to AWS and Azure cloud services.





