<?php
class Solution {
/**
* @param String[] $folder
* @return String[]
*/
function removeSubfolders(array $folder): array
{
$res = [];
sort($folder);
$res[] = $folder[0];
$len = count($folder);
for ($i = 1; $i < $len; $i++) {
if (strpos($folder[$i],$res[count($res)-1].'/') !== 0 || $folder[$i] == '/') {
$res[] = $folder[$i];
}
}
return $res;
}
}
$solution = new Solution();
var_dump($solution->removeSubfolders(["/c","/d/c/e"]));
力扣1233
最新推荐文章于 2024-11-04 14:35:43 发布