题目描述:

leetcode-71-简化路径

leetcode-71-简化路径

方法:

class Solution: 
    def simplifyPath(self, path: str) -> str: 
        stack = [] 
        path = path.split("/") 
        for item in path: 
            if item == "..": 
                if stack : 
                    stack.pop() 
            elif item and item != ".": 
                stack.append(item) 
        return "/" + "/".join(stack)

 

相关文章:

  • 2021-07-13
  • 2021-07-11
  • 2022-01-12
  • 2021-05-08
  • 2022-12-23
  • 2022-12-23
  • 2021-08-24
  • 2022-03-01
猜你喜欢
  • 2021-08-16
  • 2022-12-23
  • 2022-12-23
  • 2021-09-03
  • 2021-12-19
  • 2022-12-23
  • 2021-09-04
相关资源
相似解决方案