Skip to content

Commit 0b09d13

Browse files
committed
Runtime: 10 ms (Top 59.80%) | Memory: 10.6 MB (Top 29.82%)
1 parent 843c29f commit 0b09d13

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,48 @@
1-
// 😉😉😉😉Please upvote if it helps 😉😉😉😉
1+
// Runtime: 10 ms (Top 59.80%) | Memory: 10.6 MB (Top 29.82%)
2+
// Please upvote if it helps
23
class Solution {
34
public:
45
string simplifyPath(string path) {
5-
6+
67
stack<string> st;
78
string res;
8-
9-
for(int i = 0; i<path.size(); ++i)
9+
10+
for(int i = 0; i<path.size(); ++i)
1011
{
11-
if(path[i] == '/')
12+
if(path[i] == '/')
1213
continue;
1314
string temp;
14-
// iterate till we doesn't traverse the whole string and doesn't encounter the last /
15+
// iterate till we doesn't traverse the whole string and doesn't encounter the last /
1516
while(i < path.size() && path[i] != '/')
1617
{
17-
// add path to temp string
18+
// add path to temp string
1819
temp += path[i];
1920
++i;
2021
}
2122
if(temp == ".")
2223
continue;
23-
// pop the top element from stack if exists
24+
// pop the top element from stack if exists
2425
else if(temp == "..")
2526
{
2627
if(!st.empty())
2728
st.pop();
2829
}
2930
else
30-
// push the directory file name to stack
31+
// push the directory file name to stack
3132
st.push(temp);
3233
}
33-
34-
// adding all the stack elements to res
34+
35+
// adding all the stack elements to res
3536
while(!st.empty())
3637
{
3738
res = "/" + st.top() + res;
3839
st.pop();
3940
}
40-
41-
// if no directory or file is present
41+
42+
// if no directory or file is present
4243
if(res.size() == 0)
4344
return "/";
44-
45+
4546
return res;
4647
}
47-
};
48+
};

0 commit comments

Comments
 (0)