Skip to content

Commit f90f3f8

Browse files
authored
Add files via upload
1 parent d62c6c0 commit f90f3f8

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
71. Simplify Path(Medium)
2+
3+
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.
4+
5+
In a Unix-style file system, a period '.' refers to the current directory, a double period '..' refers to the directory up a level, and any multiple consecutive slashes (i.e. '//') are treated as a single slash '/'. For this problem, any other format of periods such as '...' are treated as file/directory names.
6+
7+
The canonical path should have the following format:
8+
9+
The path starts with a single slash '/'.
10+
Any two directories are separated by a single slash '/'.
11+
The path does not end with a trailing '/'.
12+
The path only contains the directories on the path from the root directory to the target file or directory (i.e., no period '.' or double period '..')
13+
Return the simplified canonical path.
14+
15+
16+
17+
Example 1:
18+
19+
Input: path = "/home/"
20+
Output: "/home"
21+
Explanation: Note that there is no trailing slash after the last directory name.
22+
Example 2:
23+
24+
Input: path = "/../"
25+
Output: "/"
26+
Explanation: Going one level up from the root directory is a no-op, as the root level is the highest level you can go.
27+
Example 3:
28+
29+
Input: path = "/home//foo/"
30+
Output: "/home/foo"
31+
Explanation: In the canonical path, multiple consecutive slashes are replaced by a single one.
32+
33+
34+
Constraints:
35+
36+
1 <= path.length <= 3000
37+
path consists of English letters, digits, period '.', slash '/' or '_'.
38+
path is a valid absolute Unix path.

0 commit comments

Comments
 (0)