Horje
1047. Remove All Adjacent Duplicates In String solution leetcode in c++ Code Example
1047. Remove All Adjacent Duplicates In String solution leetcode in c++
#include<iostream>
#include<stack>
using namespace std;
string removeDuplicates(string s) {
	stack<char> ss;
	for (int i = 0; i < s.length(); i++)
	{
		if (ss.empty())
		{
			ss.push(s[i]);
		}
		else
		{
			if (ss.top() == s[i])
			{
				ss.pop();
			}
			else
			{
				ss.push(s[i]);
			}
		}
	}
	string s2;
	while (ss.size())
	{
		s2.push_back(ss.top());
		ss.pop();
	}
	reverse(s2.begin(), s2.end());
	return s2;
}
int main()
{
	string s;
	cin >> s;
	string result = removeDuplicates(s);
	cout << result << "\n";
	return 0;
}




Cpp

Related
how to create a c++ templeate Code Example how to create a c++ templeate Code Example
c++ to find size of char Code Example c++ to find size of char Code Example
i2c slave onreceive Code Example i2c slave onreceive Code Example
C++ Calculating the Mode of a Sorted Array Code Example C++ Calculating the Mode of a Sorted Array Code Example
Inverse Square Code Example Inverse Square Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
11