Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- string simplifyPath(string path) {
- string res, tmp;
- vector<string> stk;
- stringstream ss(path);
- while(getline(ss,tmp,'/')) {
- if(tmp == "" or tmp == ".") continue;
- if(tmp == ".."){
- if(!stk.empty())
- stk.pop_back();
- }
- else stk.push_back(tmp);
- }
- for(auto str : stk) res += "/"+str;
- return res.empty() ? "/" : res;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement