mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 11:34:46 +08:00
optimize
This commit is contained in:
@ -264,14 +264,15 @@ javaScript:
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
var removeDuplicates = function(s) {
|
var removeDuplicates = function(s) {
|
||||||
const stack = [];
|
const result = []
|
||||||
for(const x of s) {
|
for(const i of s){
|
||||||
let c = null;
|
if(i === result[result.length-1]){
|
||||||
if(stack.length && x === (c = stack.pop())) continue;
|
result.pop()
|
||||||
c && stack.push(c);
|
}else{
|
||||||
stack.push(x);
|
result.push(i)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return stack.join("");
|
return result.join('')
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user