Skip to content

Latest commit

 

History

History
20 lines (18 loc) · 471 Bytes

071.md

File metadata and controls

20 lines (18 loc) · 471 Bytes

71. Simplify Path

Solution 1

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