Home | Projects | Notes > Problem Solving > LC - E - 1047. Remove All Adjacent Duplicates In String 1 (stack)

LC - E - 1047. Remove All Adjacent Duplicates In String 1 (stack)

 

Solutions in C++

Solution 1

This solution uses STL stack container.

The original string does not get modified.

Complexity Analysis:

Solution:

 

Solution 2

This solution uses STL stack container.

The original string gets modified.

Be careful when using the member function erase(). Following statement will erase everything from s[i] on:

I had to spend quite some time debugging it.

Complexity Analysis:

Solution:

 

Solution 3

This solution solves the problem without using the STL stack container. Instead, a string object is used to build up the string to return.

Complexity Analysis:

Solution: