Package g0001_0100.s0071_simplify_path
Class Solution
java.lang.Object
g0001_0100.s0071_simplify_path.Solution
71 - Simplify Path.<p>Medium</p>
<p>Given a string <code>path</code>, which is an <strong>absolute path</strong> (starting with a slash <code>'/'</code>) to a file or directory in a Unix-style file system, convert it to the simplified <strong>canonical path</strong>.</p>
<p>In a Unix-style file system, a period <code>'.'</code> refers to the current directory, a double period <code>'..'</code> refers to the directory up a level, and any multiple consecutive slashes (i.e. <code>'//'</code>) are treated as a single slash <code>'/'</code>. For this problem, any other format of periods such as <code>'...'</code> are treated as file/directory names.</p>
<p>The <strong>canonical path</strong> should have the following format:</p>
<ul>
<li>The path starts with a single slash <code>'/'</code>.</li>
<li>Any two directories are separated by a single slash <code>'/'</code>.</li>
<li>The path does not end with a trailing <code>'/'</code>.</li>
<li>The path only contains the directories on the path from the root directory to the target file or directory (i.e., no period <code>'.'</code> or double period <code>'..'</code>)</li>
</ul>
<p>Return <em>the simplified <strong>canonical path</strong></em>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> path = “/home/”</p>
<p><strong>Output:</strong> “/home”</p>
<p><strong>Explanation:</strong> Note that there is no trailing slash after the last directory name.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> path = “/../”</p>
<p><strong>Output:</strong> “/”</p>
<p><strong>Explanation:</strong> Going one level up from the root directory is a no-op, as the root level is the highest level you can go.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> path = “/home//foo/”</p>
<p><strong>Output:</strong> “/home/foo”</p>
<p><strong>Explanation:</strong> In the canonical path, multiple consecutive slashes are replaced by a single one.</p>
<p><strong>Example 4:</strong></p>
<p><strong>Input:</strong> path = “/a/./b/../../c/”</p>
<p><strong>Output:</strong> “/c”</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= path.length <= 3000</code></li>
<li><code>path</code> consists of English letters, digits, period <code>'.'</code>, slash <code>'/'</code> or <code>'_'</code>.</li>
<li><code>path</code> is a valid absolute Unix path.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
simplifyPath
-