C# Solution


  • 0
    M
    public bool IsPalindrome(string s) {
        Stack<char> stack = new Stack<char>(); 
        Queue<char> queue = new Queue<char>(); 
        s = s.ToLower(); 
        int charCount = 0; 
        
        foreach(char c in s)
        {
            if ((c >= 'a' && c <= 'z') || (c >= '0' && c <='9'))
            {
                stack.Push(c);
                queue.Enqueue(c);    
                charCount++;
            }
        }
        
        for (int i = 0; i < charCount /2 ; i++)
        {
            if (stack.Pop() != queue.Dequeue()) return false; 
        }
           
        return true; 
    }

Log in to reply
 

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