Skip to content

Commit 1d1f213

Browse files
committed
cleaned up
1 parent 63cdb37 commit 1d1f213

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

javascript/1209-Remove-All-Adjacent-Duplicates-in-String-II.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,19 @@
44
* @return {string}
55
*/
66
var removeDuplicates = function (s, k) {
7-
const stack = [];
7+
const stack = []; // [char, count];
88

99
for (const c of s) {
10-
// Construct stack
1110
if (stack.length !== 0 && stack[stack.length - 1][0] === c) {
1211
stack[stack.length - 1][1]++;
1312
} else {
1413
stack.push([c, 1]);
1514
}
1615

17-
// Remove from stack
1816
if (stack[stack.length - 1][1] === k) {
1917
stack.pop();
2018
}
2119
}
2220

23-
// Build output of remaining characters
2421
return stack.reduce((res, el) => (res += el[0].repeat(el[1])), '');
2522
};

0 commit comments

Comments
 (0)