diff --git a/problems/1047.删除字符串中的所有相邻重复项.md b/problems/1047.删除字符串中的所有相邻重复项.md index 8b761be7..9ca08c96 100644 --- a/problems/1047.删除字符串中的所有相邻重复项.md +++ b/problems/1047.删除字符串中的所有相邻重复项.md @@ -186,6 +186,24 @@ class Solution: 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(""); +}; +```