C++ hashset  4 line solution
The first one is my favorite because, idea-wise, it\'s simple and natural to what we are searching for. \nPlus easy to be debugged for potential issues.\n\nTo p
The first one is my favorite because, idea-wise, it\'s simple and natural to what we are searching for. \nPlus easy to be debugged for potential issues.\n\nTo prove the point, I also provided the other 3 popular solution at the end of the post.\n\n```\nclass Solution {//Hashset\npublic: // Time/Space: O(N), O(N)\n  string destCity(vector<vector<string>>& paths) {                \n        unordered_set<string> startingCities;\n        for(auto& e: paths)  startingCities.insert(e[0]);                        \n        for(auto& e: paths) \n            if(!startingCities.count(e[1])) return e[1];             \n        return "";\n    }\n};\n```\n\n```\nclass Solution {\npublic:\n  string destCity(vector<vector<string>>& paths) {\n        unordered_map<string, int> degreeMap;        \n        for(auto& e: paths){\n            degreeMap[e[0]] += 1;\n            degreeMap[e[1]] += 0;\n        }\n        \n        for (auto& [k, v]: degreeMap)\n            if (v == 0)\n                return k;\n        return ""; // Note1:\n    }\n};\n/*\nNote1: without this, C++ will issue warning:\nfatal error: control may reach end of non-void function\n*/\n```\n\n```\nclass Solution {\npublic:\n  string destCity(vector<vector<string>>& paths) {\n        unordered_map<string, string> m;\n        for(auto& e: paths)     m[e[0]] = e[1];\n        string cur(paths[0][0]);\n        while(m.count(cur))\n            cur = m[cur];\n        return cur;\n    }\n};\n```\n\n```\nclass Solution {\npublic:\n  string destCity(vector<vector<string>>& paths) {\n        string des;\n        for(int i=0;i<paths.size();i++){ \n                int t=0; // 0: w/o outlet; 1: w output\n                string& tmp=paths[i][1];\n                for(int j=0;j<paths.size();j++)\n                    if(paths[j][0]==tmp){\n                        t=1;break;\n                    }\n                if(t==0){\n                    des=tmp;\n                    break;\n                }\n        }\n        return des;\n    }\n};\n\n```\n\nNote1: Optmization. \n@fetag mention find() is faster than count() in C++ set. I can not confirm. If anybody can help here, please comment.\nMy personal reason to prefer count() is its brevity. \n\n\nruntime efficency of find based variation for  version 1\n\nRuntime: 20 ms, faster than 96.29% of C++ online submissions for Destination City.\nMemory Usage: 10.9 MB, less than 69.74% of C++ online submissions for Destination City.\n\nRuntime: 16 ms, faster than 99.34% of C++ online submissions for Destination City.\nMemory Usage: 11 MB, less than 60.32% of C++ online submissions for Destination City.\n\n\nRuntime: 20 ms, faster than 96.29% of C++ online submissions for Destination City.\nMemory Usage: 10.7 MB, less than 87.69% of C++ online submissions for Destination City.\n\n\nruntime efficency of cout based variation for  version 1:\n\nRuntime: 16 ms, faster than 99.34% of C++ online submissions for Destination City.\nMemory Usage: 10.9 MB, less than 69.30% of C++ online submissions for Destination City.\n\n\nRuntime: 20 ms, faster than 96.29% of C++ online submissions for Destination City.\nMemory Usage: 10.7 MB, less than 88.89% of C++ online submissions for Destination City.\n\nRuntime: 24 ms, faster than 84.40% of C++ online submissions for Destination City.\nMemory Usage: 10.7 MB, less than 88.95% of C++ online submissions for Destination City.\n\n\nP.S.:\nIf you love sexy short solution, you may also wish to check my new post:\nhttps://leetcode.com/problems/insert-delete-getrandom-o1/discuss/685574/challenge-me-for-shorter-solution-4-line/578174
[]