Gary Lai
  • Home
  • About
Sign in Subscribe

71. Simplify Path

Last updated on  Apr 2, 2025

71. Simplify Path

class Solution:
    def simplifyPath(self, path: str) -> str:
        
        tmp = path.split('/')
        res = []
        for item in tmp:
            if item == '' or item == '.':
                continue
            elif item == '..':
                if len(res) > 0:
                    res.pop()
            else:
                res.append(item)
        
        return "/" + "/".join(res)
Previous 844. Backspace String Compare
Next 1544. Make The String Great
Gary Lai © 2025
  • Sign up
Powered by Ghost