aboutsummaryrefslogtreecommitdiff
path: root/misc.cpp
blob: 82632443196ddcf2dd9dbbc0cb62a004c2e1fcbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Solution {
public:
  vector<string> removeSubfolders(vector<string> &folder) {
    sort(folder.begin(), folder.end());
    vector<string> res;

    for (auto s : folder) {
      if (res.size() == 0) {
        res.push_back(s);
        continue;
      }

      string parent = res[res.size() - 1];
      if (s.substr(0, parent.size() + 1) != parent + '/')
        res.push_back(s);
    }

    return res;
  }
};