Skip to content

Commit 3f99b2e

Browse files
committed
Added solution of Simplify Path in cpp
1 parent 68fe248 commit 3f99b2e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

71.Simplify Path.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
string simplifyPath(string path) {
4+
string res, tmp;
5+
vector<string> stk;
6+
stringstream ss(path);
7+
while(getline(ss,tmp,'/')) {
8+
if (tmp == "" or tmp == ".") continue;
9+
if (tmp == ".." and !stk.empty()) stk.pop_back();
10+
else if (tmp != "..") stk.push_back(tmp);
11+
}
12+
for(auto str : stk) res += "/"+str;
13+
return res.empty() ? "/" : res;
14+
}
15+
};

0 commit comments

Comments
 (0)