题解 | #点击消除#
点击消除
http://www.nowcoder.com/practice/8d3643ec29654cf8908b5cf3a0479fd5
let stack = [];
for (let i = 0; i < line.length; ) {
if (line[i] === stack[stack.length - 1]) {
stack.pop();
} else {
stack.push(line[i]);
}
i++;
}
if (stack.length == 0) {
console.log("0");
} else {
console.log(stack.join(""));
}