美文网首页
71. Simplify Path

71. Simplify Path

作者: 羲牧 | 来源:发表于2020-06-01 21:57 被阅读0次

此题用C写起来估计还是很有难度的

class Solution:
    def simplifyPath(self, path: str) -> str:
        path = path.strip().split('/')
        stack = []
        for i in path:
            if i == '..':
                if len(stack) > 0:
                    stack.pop()
                else:
                    continue
            elif i == '.' or i == '':
                continue
            else:
                stack.append(i)
        
        print(stack)
        return '/' + '/'.join(stack)
                




相关文章

网友评论

      本文标题:71. Simplify Path

      本文链接:https://www.haomeiwen.com/subject/xteezhtx.html