# [71\. Simplify Path](https://leetcode.com/problems/simplify-path/) :::spoiler Solution ```cpp= class Solution { public: string simplifyPath(string path) { vector<string> dir; stringstream ss(path); string token; while(getline(ss, token, '/')) { if(token == "..") { if (!dir.empty()) dir.pop_back(); } else if (!token.empty() && token != ".") { dir.push_back(token); } } string res; for (auto s : dir) res += "/" + s; return res.empty() ? "/" : res; } }; ``` - T: $O(n)$ - S: $O(n)$ :::