문제 링크 : https://leetcode.com/problems/simplify-path/description/
주어진 경로를 단순화하여 반환하는 문제이다.
우선 주어진 경로//에서 /들을 빼준 담애
주어진 조건들을 만족하도록 구현한 것을 stack에 넣어주고
마지막으로 /와 같이 조인해주어 반환하면 된다.
class Solution:
def simplifyPath(self, path: str) -> str:
stack = []
path = path.split('/')
for i in path:
if not i or i == "." :
continue
elif i == "..":
if stack:
stack.pop()
else:
stack.append(i)
return "/"+ "/".join(stack)