aboutsummaryrefslogtreecommitdiff
path: root/other/simplify_path.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'other/simplify_path.cpp')
-rw-r--r--other/simplify_path.cpp33
1 files changed, 0 insertions, 33 deletions
diff --git a/other/simplify_path.cpp b/other/simplify_path.cpp
deleted file mode 100644
index 09852f3..0000000
--- a/other/simplify_path.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-// 71. Simplify Path
-#include "leetcode.h"
-
-// given a string 'path', which is an absolute path (starting with a slash) to a
-// file or directory in a unix-style file system, convert it to the simplified
-// canonical path
-
-class Solution {
-public:
- string simplifyPath(string path) {
- vector<string> stack;
- string ans, tmp;
- stringstream p(path);
- while (getline(p, tmp, '/')) {
- if (tmp == "" || tmp == ".")
- continue;
- if (!stack.empty() && tmp == "..")
- stack.pop_back();
- else if (tmp != "..")
- stack.push_back(tmp);
- }
- for (auto s : stack)
- ans += "/" + s;
- return stack.empty() ? "/" : ans;
- }
-};
-
-int main() {
- Solution obj;
- cout << obj.simplifyPath("/home/") << endl; // expect: /home/
- cout << obj.simplifyPath("/../") << endl; // expect: /
- cout << obj.simplifyPath("/home//foo/") << endl; // expect: /home/foo
-}