leetcode71. 简化路径

 

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)

  

 

posted @ 2023-09-17 17:19  Aneverforget  阅读(3)  评论(0编辑  收藏  举报