Simple Python Solution


  • 0
    Y
    
     def simplifyPath(self, path):
            items = path.split("/")
            stack = []
            for i,v in enumerate(items):
                if v == "..":
                    if stack != []:
                      stack.pop()
                elif v != "." and v != "":
                    stack.append(v)
            return "/" + "/".join(stack)

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.