Remove All Adjacent Duplicates In String
就是找到并且去除回文啊。。用stack检查
class Solution {
public String removeDuplicates(String S) {
Stack st = new Stack();
for(int i = 0; i < S.length(); i++) {
if(!st.empty() && S.charAt(i) == st.peek()) //find
st.pop();
else
st.push(S.charAt(i));
}
StringBuffer sb = new StringBuffer();
int n = st.size();
for(int i = 0 ; i < n; i++) {
sb.append(st.pop());
}
sb.reverse();
return sb.toString();
}
}