-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathAnswer78.cpp
35 lines (29 loc) · 886 Bytes
/
Answer78.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<stack>
bool findRedundantBrackets(string &s)
{
stack<char> st;
for(int i=0; i<s.length(); i++) {
char ch =s[i];
if(ch == '(' || ch == '+' ||ch == '-' || ch == '*' || ch == '/') {
st.push(ch);
}
else
{
//ch ya toh ')' hai or lowercase letter
if(ch == ')') {
bool isRedundant = true;
while(st.top() != '(') {
char top = st.top();
if(top == '+' ||top == '-' || top == '*' || top == '/') {
isRedundant = false;
}
st.pop();
}
if(isRedundant == true)
return true;
st.pop();
}
}
}
return false;
}