1
class Solution {
2
public String removeDuplicates(String s) {
3
Stack<Character> st = new Stack<>();
4
int i = s.length() - 1;
5
while (i >= 0) {
6
char ch = s.charAt(i);
7
if (st.size() > 0 && ch == st.peek()) {
8
st.pop();
9
} else {
10
st.push(ch);
11
}
12
i--;
13
}
14
StringBuilder ans = new StringBuilder("");
15
while (!st.isEmpty()) {
16
ans.append(st.pop());
17
}
18
return ans.toString();
19
}
20
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0