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)
When execution: 28 ms, beat the 64.37% of all users to submit in python
Memory consumption: 11.6 MB, defeated 30.41% of all users to submit in python
——2019.11.2