Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def simplifyPath(self, path):
- """
- :type path: str
- :rtype: str
- """
- l = path.split('/')
- dirs = []
- for x in l:
- if x == '.' or x == '':
- continue
- elif x == '..':
- if dirs:
- dirs.pop()
- else:
- dirs.append(x)
- if not dirs:
- return '/'
- result = ''
- for d in dirs:
- result += '/{}'.format(d)
- return result
Add Comment
Please, Sign In to add comment