We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 68fe248 commit 3f99b2eCopy full SHA for 3f99b2e
71.Simplify Path.cpp
@@ -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