Skip to content

Latest commit

 

History

History
26 lines (21 loc) · 451 Bytes

71.md

File metadata and controls

26 lines (21 loc) · 451 Bytes

题目地址

https://leetcode-cn.com/problems/simplify-path/

解答

def simplifyPath(path):
    """
        简化路径

        输入:"/a//b////c/d//././/.."
        输出:"/a/b/c"
    """
    s = path.split('/')
    res = []

    for x in s:
        if x:
            if x == '..':
                if res:
                    res.pop()
            elif x != '.':
                res.append(x)

    return '/' + '/'.join(res)