-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq_071_simplify_path.py
More file actions
24 lines (21 loc) · 883 Bytes
/
Copy pathq_071_simplify_path.py
File metadata and controls
24 lines (21 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution:
def simplifyPath(self, path: str) -> str:
proper_path_stack = []
folders = path.split('/')
for f in folders:
if f == '..':
if len(proper_path_stack) > 0:
proper_path_stack.pop()
elif f != '' and f != '.':
proper_path_stack.append(f)
# ######################################################
# ######## these lines can be written in one line
# ######################################################
# proper_path = ''
# for f in proper_path_stack:
# proper_path = proper_path + '/' + f
# if len(proper_path) == 0:
# proper_path = '/'
proper_path = '/' + '/'.join(proper_path_stack)
# ######################################################
return proper_path