Horje
valid parentheses in cpp Code Example
valid parentheses in cpp
#include<iostream>
#include<stack>
using namespace std;
bool isValid(string s) {
	stack<char> st;
	for (int i = 0; i < s.length(); i++)
	{
		if (s[i] == '(' || s[i] == '{' || s[i] == '[')
			st.push(s[i]);
		if (!st.empty())
		{
			if (s[i] == ')')
			{
				if (st.top() == '(')
				{
					st.pop();
					continue;
				}
				else
					break;
			}
			//
			if (s[i] == '}')
			{
				if (st.top() == '{')
				{
					st.pop();
					continue;
				}
				else
					break;
			}
			//
			if (s[i] == ']')
			{
				if (st.top() == '[')
				{
					st.pop();
					continue;
				}
				else
					break;
			}
		}
		else
			return false;
	}
	return st.empty() ? true : false;
}
int main()
{
	string s;
	cin >> s;
	cout << isValid(s) << "\n";
	return 0;
}




Cpp

Related
stack implementation through linked list Code Example stack implementation through linked list Code Example
sort index c++ Code Example sort index c++ Code Example
c++ multiply char Code Example c++ multiply char Code Example
find substring in string c++ Code Example find substring in string c++ Code Example
How to use jwt in login api in node js Code Example How to use jwt in login api in node js Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
11