mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
添加1047. 删除字符串中的所有相邻重复项javaScript版本
This commit is contained in:
@ -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("");
|
||||
};
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user