Guest User

Untitled

a guest
Mar 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. class Solution:
  2. def simplifyPath(self, path):
  3. """
  4. :type path: str
  5. :rtype: str
  6. """
  7. l = path.split('/')
  8.  
  9. dirs = []
  10. for x in l:
  11. if x == '.' or x == '':
  12. continue
  13. elif x == '..':
  14. if dirs:
  15. dirs.pop()
  16. else:
  17. dirs.append(x)
  18.  
  19. if not dirs:
  20. return '/'
  21. result = ''
  22. for d in dirs:
  23. result += '/{}'.format(d)
  24.  
  25. return result
Add Comment
Please, Sign In to add comment