Skip to content

Commit cb6a0d3

Browse files
authored
Create 1233_remove_subfolders_from_the_filesystem.cpp
1 parent 38deb6e commit cb6a0d3

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution {
2+
public:
3+
vector<string> removeSubfolders(vector<string>& folder) {
4+
int n = folder.size();
5+
vector<string>res;
6+
unordered_set<string>h, k;
7+
for(auto s : folder){
8+
h.insert(s);
9+
}
10+
for(int i=0;i<n;i++){
11+
string s = folder[i];
12+
for(int j = 1; j<s.size();j++){
13+
if(s[j]=='/'){
14+
if(h.find(s.substr(0, j))!=h.end()){
15+
k.insert(s.substr(0, j));
16+
break;
17+
}
18+
}
19+
if(j==s.size()-1){
20+
k.insert(s);
21+
}
22+
}
23+
}
24+
for(auto s : k){
25+
res.push_back(s);
26+
}
27+
return res;
28+
}
29+
};

0 commit comments

Comments
 (0)