Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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 << "
";
	return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ unordered set count 
Cpp :: C++ with SVD 
Cpp :: qt c++ thread example 
Cpp :: glm multiply vector by scalar 
Cpp :: deal with bad input cpp 
Cpp :: python Difference Array | Range update query in O(1) 
Cpp :: type defination in C++ 
Cpp :: std 
Cpp :: ex:Roblox 
Cpp :: auto keyword 
Cpp :: comment savoir si un nombre est premier c++ 
Cpp :: Problems in your to-do list codechef solution in c++ 
Cpp :: sort in descending order c++ 
Cpp :: & before function arg in cpp 
Cpp :: 1281. Subtract the Product and Sum of Digits of an Integer leetcode solution in c++ 
Cpp :: bitmap rotate 90 deg 
Cpp :: how to input a file path in c++ 
Cpp :: std::string(size_t , char ) constructor: 
Cpp :: prime template c++ 
Cpp :: In every C++ program: 
Cpp :: c++ get last element in array 
Cpp :: 18 in 12 hour time 
Cpp :: C++ Area and Circumference of a Circle 
Cpp :: equal elements in two arrays in c++ 
Cpp :: c++ environment setup 
C :: auto click connect colab 
C :: How to install npm in alpine linux 
C :: octave square each element matrix 
C :: c print size_t 
C :: remove element from np array 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =