Skip to content

Commit a98fdda

Browse files
committed
Add solution #1047
1 parent 89f880b commit a98fdda

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@
269269
1022|[Sum of Root To Leaf Binary Numbers](./1022-sum-of-root-to-leaf-binary-numbers.js)|Easy|
270270
1037|[Valid Boomerang](./1037-valid-boomerang.js)|Easy|
271271
1041|[Robot Bounded In Circle](./1041-robot-bounded-in-circle.js)|Medium|
272+
1047|[Remove All Adjacent Duplicates In String](./1047-remove-all-adjacent-duplicates-in-string.js)|Easy|
272273
1071|[Greatest Common Divisor of Strings](./1071-greatest-common-divisor-of-strings.js)|Easy|
273274
1081|[Smallest Subsequence of Distinct Characters](./1081-smallest-subsequence-of-distinct-characters.js)|Medium|
274275
1103|[Distribute Candies to People](./1103-distribute-candies-to-people.js)|Easy|
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* 1047. Remove All Adjacent Duplicates In String
3+
* https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string/
4+
* Difficulty: Easy
5+
*
6+
* You are given a string s consisting of lowercase English letters. A duplicate removal
7+
* consists of choosing two adjacent and equal letters and removing them.
8+
*
9+
* We repeatedly make duplicate removals on s until we no longer can.
10+
*
11+
* Return the final string after all such duplicate removals have been made. It can be
12+
* proven that the answer is unique.
13+
*/
14+
15+
/**
16+
* @param {string} s
17+
* @return {string}
18+
*/
19+
var removeDuplicates = function(s) {
20+
const stack = [];
21+
22+
for (const char of s) {
23+
stack[stack.length - 1] === char ? stack.pop() : stack.push(char);
24+
}
25+
26+
return stack.join('');
27+
};

0 commit comments

Comments
 (0)