0%

LeetCode: 71. Simplify Path

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution(object):
def simplifyPath(self, path):
"""
:type path: str
:rtype: str
"""
stack = []
items = path.split('/')
for item in items:
if item=='.' or not item:
continue
elif item=='..':
stack = stack[:-1];
else:
stack.append(item)
return '/'+'/'.join(stack)