leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1233.cpp (442B)


      1 class Solution {
      2   public:
      3     vector<string> removeSubfolders(vector<string> &folder) {
      4         sort(folder.begin(), folder.end());
      5         vector<string> res = {folder[0]};
      6 
      7         for (int i = 1; i < folder.size(); i++) {
      8             const string root = res.back() + "/";
      9             const string prefix = folder[i].substr(0, root.size());
     10             if (prefix != root) res.push_back(folder[i]);
     11         }
     12 
     13         return res;
     14     }
     15 };