AboveYunhai 最近的时间轴更新
AboveYunhai

AboveYunhai

V2EX 第 502060 号会员,加入于 2020-08-03 05:26:55 +08:00
AboveYunhai 最近回复了
2020-08-04 09:11:52 +08:00
回复了 einq7 创建的主题 程序员 二维数组中如何去除有被其他数组元素包含的元素
@SakuraSa @einq7 前缀树代码有些 bug 和部分情况没有处理,而且可以在建立前缀树的时候同时对数据进行处理,这样数据只需要走一遍了,只修改了一点同时减少了代码量。

```js
function filter_file_path(path_list) {
// build perfixes tree
let root = {'__size__': 0};
var output = [];
path_list.forEach(path => {
var state = {'node': root};
var update = false;
path.forEach(part => {
if (state.node[part] === undefined) {
update=true;
state.node[part] = {'__size__': 0};
state.node.__size__ ++;
}
state.node = state.node[part];
});
//new tree, add to output list
if(update === true) {
output.push(path);
update=false;
}
});
return output;
}
```
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1341 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 11ms · UTC 17:48 · PVG 01:48 · LAX 10:48 · JFK 13:48
Developed with CodeLauncher
♥ Do have faith in what you're doing.