class Solution:
def simplifyPath(self, path: str) -> str:
path_segments = path.split('/')
simplified_path = []
for p in path_segments:
if p == '..':
if simplified_path:
simplified_path.pop()
elif p == '/' or p == '.':
pass
else:
if p:
simplified_path.append(p)
return "/" + "/".join(simplified_path)
O(N)
(N: path
의 길이)O(N)