Skip to content

Commit b6ef758

Browse files
authored
Added C++ code for stack problem - Remove all adjacent duplicates in string (codedecks-in#92)
* Added C++ code for stack question- Remove all adjacent duplicates in String * Updated README.md * Update README.md * Update README.md * Updated README.md
1 parent b6b8ae5 commit b6ef758

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class Solution {
2+
public:
3+
string removeDuplicates(string str) {
4+
stack<char> s;
5+
string answer="";
6+
for(int i=0;i<str.length();i++)
7+
{
8+
if(s.empty())
9+
s.push(str[i]);
10+
else if(str[i]==s.top())
11+
{
12+
s.pop();
13+
}
14+
else
15+
s.push(str[i]);
16+
}
17+
while(!s.empty())
18+
{
19+
answer.push_back(s.top()); //pop values from stack and add it to back of the string answer(hense answer string is in reverse order)
20+
s.pop();
21+
}
22+
auto it=answer.rbegin();
23+
string val="";
24+
for (; it!=answer.rend(); it++) //this reverses the answer string
25+
{
26+
val.push_back(*it);
27+
}
28+
return val;
29+
}
30+
};

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
155155
| --- | --------------------------------------------------------------------------------------------------- | ------------------------------------------------------- | ------ | ------ | ---------- | ----- | ---- |
156156
| 020 | [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/) | [Python](./Python/20_ValidParentheses.py) | _O(n)_ | _O(n)_ | Easy | Stack | |
157157
| 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation/) | [Python](./Python/150.EvaluateReversePolishNotation.py) | _O(n)_ | _O(1)_ | Medium | Stack | |
158+
| 1047 | [Remove All Adjacent Duplicates In String](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string/) | [C++](./C++/remove-all-adjacent-duplicates-in-string.cpp) | _O(n)_ | _O(n)_ | Easy | Stack | |
159+
158160

159161
<br/>
160162
<div align="right">
@@ -393,7 +395,8 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if
393395
| [Hardik Gupta](https://github.com/harrdy272) <br> <img src="https://avatars3.githubusercontent.com/u/42604986?s=460&u=609a0839312a620d3d658ef19e8eac1e226a6eb4&v=4" width="100" height="100"> | India | C++ | [codeforces](https://codeforces.com/profile/harrdy272) <br>[codechef](https://www.codechef.com/users/hardikg272) <br> [Hackerrank](https://www.hackerrank.com/hardikg272) <br> [LeetCode](https://leetcode.com/hardikg272/) |
394396
| [Jaseem ck](https://github.com/Jaseemck) <br> <img src="https://github.com/Optider.png" width="100" height="100"> | India | Python | [Github](https://github.com/Jaseemck) |
395397
| [Ilias Khan](https://github.com/IliasKhan) <br> <img src="https://avatars3.githubusercontent.com/u/26863936?s=460&u=4501ffba5efd1a7b978416e8e434dff599c85384&v=4" width="100" height="100"> | India | C++ | [codechef](https://www.codechef.com/users/iliaskhan) <br> [Hackerrank](ckerrank.com/iliaskhan57) <br> [LeetCode](https://leetcode.com/ilias_khan/) <br> [codeforces](http://codeforces.com/profile/iliaskhan) |
396-
398+
| [Shamoyeeta Saha](https://github.com/Shamoyeeta) <br> <img src="https://i.pinimg.com/236x/dc/ef/3a/dcef3abedf0e0761203aaeb85886a6f3--jedi-knight-open-source.jpg" width="100" height="100"> | India | C++ | [Hackerrank](https://www.hackerrank.com/sahashamoyeeta) <br> [Github](https://github.com/Shamoyeeta) |
399+
|
397400
<br/>
398401
<div align="right">
399402
<b><a href="#algorithms">⬆️ Back to Top</a></b>

0 commit comments

Comments
 (0)