1233. Remove Sub-Folders from the Filesystem
思路:
先排序,排序后所有子资料夹就会接在母资料夹后
用双指标检查每个folder
若j前缀为i + "/"则j为i的子资料夹
func removeSubfolders(folder []string) []string {
sort.Strings(folder)
ans := []string{folder[0]}
i, j := 0, 1
for {
if !strings.HasPrefix(folder[j], folder[i] + "/") {
i = j
ans = append(ans, folder[i])
}
j++
if j == len(folder) {
break
}
}
return ans
}