-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathsolution.py
More file actions
16 lines (14 loc) · 411 Bytes
/
Copy pathsolution.py
File metadata and controls
16 lines (14 loc) · 411 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution:
# Time: O(n)
# Space: O(n)
def simplify_path(self, path: str) -> str:
stack: list[str] = []
for part in path.split("/"):
if part == "" or part == ".":
continue
if part == "..":
if stack:
stack.pop()
else:
stack.append(part)
return "/" + "/".join(stack)