{"id":296,"date":"2024-07-02T23:20:44","date_gmt":"2024-07-02T15:20:44","guid":{"rendered":"https:\/\/wangqianming.top\/?p=296"},"modified":"2024-07-02T23:20:44","modified_gmt":"2024-07-02T15:20:44","slug":"%e7%ae%80%e5%8c%96%e8%b7%af%e5%be%84","status":"publish","type":"post","link":"https:\/\/wangqianming.top\/index.php\/2024\/07\/02\/%e7%ae%80%e5%8c%96%e8%b7%af%e5%be%84\/","title":{"rendered":"\u7b80\u5316\u8def\u5f84"},"content":{"rendered":"<pre><code class=\"language-c\">class Solution {\npublic:\n    string simplifyPath(string path) {\n        auto split = [](const string&amp; s, char delim) -&gt; vector&lt;string&gt; {\n            vector&lt;string&gt; ans;\n            string cur;\n            for (char ch: s) {\n                if (ch == delim) {\n                    ans.push_back(move(cur));\n                    cur.clear();\n                }\n                else {\n                    cur += ch;\n                }\n            }\n            ans.push_back(move(cur));\n            return ans;\n        };\n\n        vector&lt;string&gt; names = split(path, &#039;\/&#039;);\n        vector&lt;string&gt; stack;\n        for (string&amp; name: names) {\n            if (name == &quot;..&quot;) {\n                if (!stack.empty()) {\n                    stack.pop_back();\n                }\n            }\n            else if (!name.empty() &amp;&amp; name != &quot;.&quot;) {\n                stack.push_back(move(name));\n            }\n        }\n        string ans;\n        if (stack.empty()) {\n            ans = &quot;\/&quot;;\n        }\n        else {\n            for (string&amp; name: stack) {\n                ans += &quot;\/&quot; + move(name);\n            }\n        }\n        return ans;\n    }\n};\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>class Solution { public: string simplifyPath(string path) { auto  &#8230;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[11,9],"class_list":["post-296","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-c","tag-leetcode"],"_links":{"self":[{"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/posts\/296","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/comments?post=296"}],"version-history":[{"count":1,"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/posts\/296\/revisions"}],"predecessor-version":[{"id":297,"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/posts\/296\/revisions\/297"}],"wp:attachment":[{"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/media?parent=296"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/categories?post=296"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/tags?post=296"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}