1
// Please upvote if it helps4
string simplifyPath(string path) {8
for (int i = 0; i < path.size(); ++i) {9
if (path[i] == '/') continue;11
// iterate till we doesn't traverse the whole string and doesn't encounter13
while (i < path.size() && path[i] != '/') {14
// add path to temp string18
if (temp == ".") continue;19
// pop the top element from stack if exists20
else if (temp == "..") {21
if (!st.empty()) st.pop();23
// push the directory file name to stack27
// adding all the stack elements to res29
res = "/" + st.top() + res;33
// if no directory or file is present34
if (res.size() == 0) return "/";