leetcode71. 简化路径

发布时间 2023-09-17 17:25:32作者: Aneverforget

 

class Solution:
    def simplifyPath(self, path: str) -> str:
        li=path.split("/")
        res=[]
        for i in li:
            if i=='..' and res:
                res.pop()
            if i!='.' and i!='..' and set(i)!=set(''):
                res.append(i)
        return '/'+"/".join(res)