添加1047. 删除字符串中的所有相邻重复项javaScript版本

This commit is contained in:
qingyi.liu
2021-05-26 17:16:01 +08:00
parent 64b9363cd5
commit 0bb42237a2

View File

@ -186,6 +186,24 @@ class Solution:
Go Go
javaScript:
```js
/**
* @param {string} s
* @return {string}
*/
var removeDuplicates = function(s) {
const stack = [];
for(const x of s) {
let c = null;
if(stack.length && x === (c = stack.pop())) continue;
c && stack.push(c);
stack.push(x);
}
return stack.join("");
};
```