Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
485 B
3
Indexable
Never
#include<iostream>
#include<stack>
#include<algorithm>
using namespace std;
string s;
stack<int> str;
int main(){
	int count = 0,Max = 0;
	s = "{{}()[][(]}";
	str.push(-1);
	for(int i = 0;i < s.length();i++){
		char c = (char)s[i];
		if(c == '(' || c == '{' || c == '['){
			str.push(i);
		}
		else{
			str.pop();
			if(str.empty()){
				str.push(i);
			}
			else{
				int len = i - str.top();
				Max = max(Max,len); 
			}
		}
	}
	cout << Max;
	return 0;
}