1436. Destination City 發表於 2023-12-21 | 分類於 leetcode problemsolution1234567891011121314151617181920class Solution {public: string destCity(vector<vector<string>>& paths) { unordered_map<string, string> mp; string ret; for(auto path:paths) { mp[path[0]] = path[1]; } string city = paths[0][0]; while(mp.find(city)!=mp.end()) { ret = mp[city]; city = mp[city]; } return ret; }}; analysis time complexity O(n) space complexity O(n)