```js 输入:"abbbaca" 输出:"ca" 解释:"abbbaca" => "aaca"=>"ca" ```
Activity
thxiami commentedon Apr 28, 2020
时间复杂度: O(n), n 为字符的个数
空间复杂度: O(n), 栈所用的空间
13001920223 commentedon Apr 28, 2020
在昨天瓶子酱的基础上增加了判断,如果下一个还是相同字符串,继续累加
没有测试用例,有问题欢迎指出
sisterAn commentedon Apr 28, 2020
👍👍👍
zhaojinzhao commentedon May 7, 2020
var arr = 'abbbaca'.split('');
var startIndex = 0;
while(startIndex < arr.length) {
var endIndex = startIndex;
while(arr[endIndex + 1] === arr[startIndex]) {
endIndex++;
}
if (startIndex !== endIndex) {
arr.splice(startIndex, endIndex - startIndex + 1);
startIndex = Math.max(0, startIndex - 1);
} else {
startIndex++;
}
}
arr.join('');
HanTianPeng commentedon May 10, 2020
解题思路:保证相同字符串始终作为栈的一个元素进行存储。
时间复杂度:O(n), 空间复杂度O(n)
iconWave commentedon May 29, 2020
supershutong commentedon Jul 3, 2020
这个和letcode 1209有什么区别吗,从瓶子给的示例看,这完全一样啊
haydenull commentedon Jul 8, 2020
@supershutong
可以比较下输入字符串为 "aaa" 时的结果,本题返回 "" ,之前的那题返回 "a"
qianlongo commentedon Aug 22, 2020
正则 + 递归
XW666 commentedon Apr 22, 2021
const removeDup = (s) => {
}
removeDup('abbbaca')
tomorrowIsNewDay commentedon Apr 28, 2021
function ans(str) {
// 正则+递归
const reg = /(\w)\1+/g
if(!reg.test(str)) return str
return ans(str.replace(reg, ''))
}
JohnApache commentedon Apr 29, 2021
和 删除
k位数一样的方案, 使用 带有count字段的对象 作为栈节点, 方便pop的操作,但是不同的是 边界条件的判断, 因为是 ,不知道会重复多少次,所以删除节点放到push下一个不同字符的节点前, 一起删除,还有需要注意的边界条件有两点
count累加,用于下轮判断的时候删除push前pop, 做了前面的一点的判断只会给节点的count累加值,因为没有下一轮循环了,所以需要在这个特殊的位置,做一次单独的pop