forked from ghostmkg/programming-language
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetcode_2696.java
More file actions
Latest commit
28 lines (26 loc) · 799 Bytes
/
Copy pathLeetcode_2696.java
File metadata and controls
28 lines (26 loc) · 799 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
importjava.util.Stack;
publicclassLeetcode_2696 {
publicintminLength(Strings) {
Stack<Character> st = newStack<>();
for (inti = 0; i < s.length(); i++) {
if (s.charAt(i) == 'B') {
if ((!st.isEmpty()) && (st.peek() == 'A')) {
st.pop();
continue;
}
}
if (s.charAt(i) == 'D') {
if ((!st.isEmpty()) && (st.peek() == 'C')) {
st.pop();
continue;
}
}
st.push(s.charAt(i));
}
returnst.size();
}
publicstaticvoidmain(String[] args) {
Leetcode_2696obj = newLeetcode_2696();
System.out.println(obj.minLength("ABFCACDB"));
}
}