MCPcopy Create free account
hub / github.com/Ainevsia/Leetcode-Rust / simplifyPath

Method simplifyPath

71. Simplify Path/Solution.cpp:9–23  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7class Solution {
8public:
9 string simplifyPath(string path) {
10 string buf;
11 vector<string> stk;
12 stringstream ss(path);
13 while (getline(ss, buf, '/')) {
14 if (buf == "" || buf == ".") continue;
15 if (buf == ".." and not stk.empty()) stk.pop_back();
16 else if (buf != "..") stk.push_back(buf);
17 }
18 string res;
19 for (auto str: stk) {
20 res += '/' + str;
21 }
22 return res.empty() ? "/" : res;
23 }
24};
25
26

Callers 1

mainFunction · 0.80

Calls 1

emptyMethod · 0.80

Tested by

no test coverage detected