1.leetcode1233题 删除子文件夹
很巧妙的题,字符串处理!加到hashmap里面,然后依次去判断,分割里面的''去判断
class Solution {
public List<String> removeSubfolders(String[] folder) {
Set<String> set = new HashSet<>();
List<String> res = new ArrayList<>();
for (String str : folder){
set.add(str);
}
for (String str : folder){
boolean isValid = true;
for (int i = str.length() - 1;i > 1;i--){
if (str.charAt(i) == '/'){
String temp = str.substring(0,i);
if (set.contains(temp)){
isValid = false;
}
}
}
if (isValid){
res.add(str);
}
}
return res;
}
}