Advertisement
nikunjsoni

609

May 18th, 2021
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     unordered_map<string, vector<string>> files;
  4.     vector<vector<string>> ans;
  5.     vector<vector<string>> findDuplicate(vector<string>& paths) {
  6.         for(auto content: paths){
  7.             stringstream ss(content);
  8.             string root, file;
  9.             getline(ss, root, ' ');
  10.            
  11.             while(getline(ss, file, ' ')){
  12.                 string path = root+"/"+file.substr(0, file.find('('));
  13.                 string content = file.substr(file.find('(')+1, file.find(')')-file.find('(')-1);
  14.                 files[content].push_back(path);
  15.             }
  16.         }
  17.         for(auto file: files)
  18.             if(file.second.size() > 1)
  19.                 ans.push_back(file.second);
  20.         return ans;
  21.     }
  22. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement