We will use C++ STL stack for this one. If you are using other language than you should implement stack yourself, stack basically is a sequence which has an option of accepting elements form the beginning and removing elements from the beginning. You can find more info about stack/C++ stack here. We need to keep a stack which will give the answer string. We need to loop over out string and check, if the new element which we are about to add to the stack equals to the top element of the stack, then we remove the top element of the stack, otherwise we push the new element to the top of the stack. After those operations we will be down to a stack which will contain out final answer.
No comments:
Post a Comment