-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay 113.java
More file actions
28 lines (22 loc) · 804 Bytes
/
Day 113.java
File metadata and controls
28 lines (22 loc) · 804 Bytes
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
import java.util.*;
class Solution {
public static boolean checkRedundancy(String s) {
Stack<Character> stack = new Stack<>();
for (char ch : s.toCharArray()) {
if (ch == ')') {
boolean hasOperator = false;
while (!stack.isEmpty() && stack.peek() != '(') {
char top = stack.pop();
if (top == '+' || top == '-' || top == '*' || top == '/') {
hasOperator = true;
}
}
if (!stack.isEmpty()) stack.pop();
if (!hasOperator) return true;
} else {
stack.push(ch);
}
}
return false;
}
}