Beats 100% of users with C++ || Faster Solution || Using HashMap || Easy to Understand
Intuition\n Describe your first thoughts on how to solve this problem. \n\n\n\n\n\n\nif you like the approach please upvote it\n\n\n\n\n\n\nif you like the appr
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n\n\n\n\n\nif you like the approach please upvote it\n\n\n\n![image.png](https://assets.leetcode.com/users/images/7495fea3-7639-48a4-8ad9-79dc9237db4e_1701793058.7524364.png)\n\n\nif you like the approach please upvote it\n\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nusing map\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    string destCity(vector<vector<string>>& paths) \n    {\n        unordered_map<string,int>mp1;\n        unordered_map<string,int>mp2;\n        for(int i=0;i<paths.size();i++)\n        {\n            mp1[paths[i][0]]++;\n            mp2[paths[i][1]]++;\n        }\n        for(auto it : mp2 )\n        {\n            if(mp1[it.first]==0)\n                return it.first;\n        }\n        return "";\n    }\n};\n```\n//OPTIMISE SOLUTION\n#Code \n    \n    class Solution {\n    public:\n        string destCity(vector<vector<string>>& paths) \n        {\n            unordered_map<string,int>mp;\n            for(int i=0;i<paths.size();i++)\n                mp[paths[i][0]]++;\n            for(int i=0;i<paths.size();i++ )\n            {\n                if(mp[paths[i][1]]==0)\n                    return paths[i][1];\n            }\n            return "";\n        }\n    };
['Hash Table', 'String', 'Ordered Map', 'C++']