Skip to content

Commit b9f2003

Browse files
Add files via upload
1 parent 73d6b95 commit b9f2003

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Simplify Path/Simplify_Path.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# 44ms 82.97%
2+
class Solution:
3+
def simplifyPath(self, path):
4+
"""
5+
:type path: str
6+
:rtype: str
7+
"""
8+
split_list = path.split('/')
9+
10+
index = 1
11+
while index <= len(split_list) - 1:
12+
if split_list[index] == '.' or split_list[index] == '':
13+
del split_list[index]
14+
elif split_list[index] == '..':
15+
del split_list[index]
16+
if index > 1:
17+
del split_list[index - 1]
18+
index -= 1
19+
else:
20+
index += 1
21+
22+
res = ''.join([item + '/' for item in split_list])
23+
24+
if len(res) > 1:
25+
return res[:-1]
26+
else:
27+
return res

0 commit comments

Comments
 (0)