Valid Palindrome solution in c# using RegularExpressions


  • 0
    U
    using System.Text.RegularExpressions;
    public class Solution {
        public bool IsPalindrome(string s) {
                s= Regex.Replace(s, @"[^0-9a-zA-Z]+",string.Empty).ToLower();
                var reversed=s.Reverse().ToArray();
                var actual= s.ToCharArray();
                var palindrome = true;
                for (int i = 0; i < actual.Length; i++)
                {
                    if (actual[i] != reversed[i])
                    {
                        palindrome = false;
                        break;
                    }
                }
                return palindrome;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.