> For the complete documentation index, see [llms.txt](https://nataliekung.gitbook.io/solutions/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nataliekung.gitbook.io/solutions/simplify_path.md).

# Simplify Path

string simplifyPath(string path) {

vector\<string> s;//vector当做栈

string dir;

for(auto i=path.begin();i!=path.end();){

i++;

auto j = find(i,path.end(),'/');

dir = string(i,j);

if(!dir.empty() && dir!="."){

if(dir==".."){

if(!s.empty())

s.pop\_back();

}else{

s.push\_back(dir);

}

}

i=j;

}

stringstream out;

if(s.empty())

out<<"/";

else{

for(auto i:s){

out<<"/"<\<i;

}

}

return out.str();

}
