(76). 25.4. Redundant Parenthesis - anishsingh90/Data_Structure_And_Algorithm_In_Cpp_github.io GitHub Wiki

#include <bits/stdc++.h> using namespace std;

int main(){ string s; cin >> s; stack st;

bool ans = false;

for(int i=0; i<s.size(); i++){
	if(s[i]=='+' or s[i]=='-' or s[i]=='*' or s[i]=='/'){
		st.push(s[i]);
	}
	else if(s[i] == '('){
		st.push(s[i]);
	}
	else if(s[i] == ')'){
		if(st.top() == '('){
			ans = true;
		}
		while(st.top() == '+' or st.top() == '-' or s[i] == '*' or s[i] == '/'){
			st.pop();
		}
		st.pop();
	}
}

cout << ans;
return 0;

}

/* OUTPUT: ((a+b)) 1 = redundant braces

OR

(a+b) 0 = not redundant braces */

⚠️ **GitHub.com Fallback** ⚠️