C# solution - 143ms


  • 0
    T
     public bool IsPalindrome(string s)
            {
                if (s == string.Empty)
                {
                    return true;
                }
    
                s = s.ToLower();
    
                StringBuilder builder = new StringBuilder();
    
                foreach (char item in s)
                {
                    if (Char.IsLetterOrDigit(item))
                    {
                        builder.Append(item);
                    }
                }
    
                string newS = builder.ToString();
    
                for (int i = 0, j = newS.Length - 1; i <= j; i++, j--)
                {
                    if (newS[i] != newS[j])
                    {
                        return false;
                    }
                }
    
                return true;
            }
    

Log in to reply
 

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