class Solution(object): def simplifyPath(self, path): """ :type path: str :rtype: str """ stack = [] items = path.split('/') for item in items: if item=='.' or not item: continue elif item=='..': stack = stack[:-1]; else: stack.append(item) return '/'+'/'.join(stack)
|