23.04.12 Today’s Leetcode
71. Simplify Path (medium)
class Solution:
def simplifyPath(self, path: str) -> str:
split = [x for x in path.split('/') if x != '']
temp = []
for p in split:
if p == '.':
continue
elif p == '..':
if len(temp) >= 1: temp.pop()
else:
temp.append(p)
# print(temp)
return '/' + '/'.join(temp)