/*
* @lc app=leetcode.cn id=1233 lang=typescript
*
* [1233] 删除子文件夹
*/
// @lc code=start
function removeSubfolders(folder: string[]): string[] {}
// @lc code=end
function removeSubfolders(folder: string[]): string[] {
const set = new Set(folder)
const res: string[] = []
next: for (const path of folder) {
const names = path.split('/')
let p = '/'
for (let i = 1; i < names.length - 1; i++) {
p += names[i]
if (set.has(p)) continue next
p += '/'
}
res.push(path)
}
return res
}
test.each([
{ input: { folder: ['/a', '/a/b', '/c/d', '/c/d/e', '/c/f'] }, output: ['/a', '/c/d', '/c/f'] },
{ input: { folder: ['/a', '/a/b/c', '/a/b/d'] }, output: ['/a'] },
{ input: { folder: ['/a/b/c', '/a/b/ca', '/a/b/d'] }, output: ['/a/b/c', '/a/b/ca', '/a/b/d'] },
])('input: folder = $input.folder', ({ input: { folder }, output }) => {
expect(removeSubfolders(folder)).toEqual(output)
})