File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 269
269
1022|[ Sum of Root To Leaf Binary Numbers] ( ./1022-sum-of-root-to-leaf-binary-numbers.js ) |Easy|
270
270
1037|[ Valid Boomerang] ( ./1037-valid-boomerang.js ) |Easy|
271
271
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|
272
273
1071|[ Greatest Common Divisor of Strings] ( ./1071-greatest-common-divisor-of-strings.js ) |Easy|
273
274
1081|[ Smallest Subsequence of Distinct Characters] ( ./1081-smallest-subsequence-of-distinct-characters.js ) |Medium|
274
275
1103|[ Distribute Candies to People] ( ./1103-distribute-candies-to-people.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments