This commit is contained in:
lzxzz
2023-04-29 09:49:25 +08:00
parent f97940758e
commit 3ff6040551

View File

@ -264,14 +264,15 @@ javaScript:
```js
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);
const result = []
for(const i of s){
if(i === result[result.length-1]){
result.pop()
}else{
result.push(i)
}
return stack.join("");
}
return result.join('')
};
```