添加1047. 删除字符串中的所有相邻重复项javaScript版本
This commit is contained in:
parent
64b9363cd5
commit
0bb42237a2
|
|
@ -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("");
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue