Clean C++ solutions using only istringstream functions

  • 0

    Though there are existing solutions using istringstream, it mostly getline the string and then use find and substr on it.
    This solution uses istringstream methods/functions directly, and I think it is cleaner :)

    vector<vector<string>> findDuplicate(vector<string>& paths) {
        unordered_map<string, vector<string>> m;
        string folder, fileName, fileContent;
        for(auto& path : paths){
            istringstream iss(path);
            iss >> folder >> ws;
            while(iss.peek() != EOF) {
                getline(iss, fileName, '(');
                getline(iss, fileContent, ')') >> ws;
        vector<vector<string>> result;
        for(auto& p : m)
            if(p.second.size() > 1)
        return result;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.