Skip to content

Commit

Permalink
Time: 43 ms (66.94%), Space: 55.3 MB (68.57%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit-S-Sahu committed Oct 25, 2024
1 parent 0bff5b2 commit cbbf816
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution {
public List<String> removeSubfolders(String[] folder) {
Arrays.sort(folder);

List<String> ans = new ArrayList<>();
ans.add(folder[0]);

for (int i = 1; i < folder.length; i++) {
String lastFolder = ans.get(ans.size() - 1) + "/";
if (!folder[i].startsWith(lastFolder)) ans.add(folder[i]);
}
return ans;
}
}

0 comments on commit cbbf816

Please sign in to comment.