diff options
author | jack <[email protected]> | 2024-06-14 13:13:15 -0600 |
---|---|---|
committer | jack <[email protected]> | 2024-06-14 13:13:15 -0600 |
commit | d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa (patch) | |
tree | 96df922dae2a5073d9a50ea70c7aae6aa37e3ebe /find_duplicate_file.cpp | |
download | leetcode-d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa.tar.gz leetcode-d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa.zip |
initial
Diffstat (limited to 'find_duplicate_file.cpp')
-rw-r--r-- | find_duplicate_file.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/find_duplicate_file.cpp b/find_duplicate_file.cpp new file mode 100644 index 0000000..17ff6f0 --- /dev/null +++ b/find_duplicate_file.cpp @@ -0,0 +1,30 @@ +#include "leetcode.h" + +class Solution { +public: + vvd(string) findDuplicate(vector<string> &paths) { + unordered_map<string, vector<string>> files; + vvd(string) ans; + for (auto &path : paths) { + int i = 0, j; + while (path[i] != ' ') + i++; + string dir = path.substr(0, i), file, content; + while (i++ < path.size()) { + j = i; + while (path[i] != '(') + i++; + file = path.substr(j, i - j); + j = i; + while (path[i++] != ')') + ; + content = path.substr(j, i - j); + files[content].emplace_back(dir + '/' + file); + } + } + for (auto &content : files) + if (content.second.size() > 1) + ans.push_back(move(content.second)); + return ans; + } +}; |