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)
原文:https://www.cnblogs.com/taoyuxin/p/11781497.html