-
Notifications
You must be signed in to change notification settings - Fork 464
Expand file tree
/
Copy path71_Simplify_Path.py
More file actions
22 lines (19 loc) · 547 Bytes
/
71_Simplify_Path.py
File metadata and controls
22 lines (19 loc) · 547 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution(object):
def simplifyPath(self, path):
"""
:type path: str
:rtype: str
"""
if not path:
return path
stack = []
for directory in path.split("/"):
if directory == "..":
if stack:
stack.pop()
elif directory == "." or not directory:
continue
else:
stack.append(directory)
finalDirectoryPath = "/" + "/".join(stack)
return finalDirectoryPath