class Solution(object): def simplifyPath(self, path): """ :type path: str :rtype: str """ stack=[] path=path.split('/') for item in path: if item=='..': if stack:stack.pop() elif item and item!='.': stack.append(item) return '/'+'/'.join(stack)
执行用时 :28 ms, 在所有 python 提交中击败了64.37%的用户
内存消耗 :11.6 MB, 在所有 python 提交中击败了30.41%的用户
——2019.11.2