Parenthesis Checker

PHOTO EMBED

Fri Feb 17 2023 09:48:31 GMT+0000 (Coordinated Universal Time)

Saved by @Ranjan_kumar #c++

class Solution
{
    public:
    //Function to check if brackets are balanced or not.
    bool ispar(string x)
    {
        stack<char> s;
        int n=x.size();
        for(int i=0;i<n;i++)
        {
            if( !s.empty()&&((s.top()=='[' && x[i]==']')||(s.top()=='{' && x[i]=='}')||(s.top() == '(' && x[i]==')' ))) 
            {
                s.pop();
            }
                
            else s.push(x[i]);
        }
        if(s.empty()) return true;
        else return false;
        // Your code here
    }

};
content_copyCOPY

https://practice.geeksforgeeks.org/problems/parenthesis-checker2744/1?utm_source=gfg&utm_medium=article&utm_campaign=bottom_sticky_on_article