Skip to content

Instantly share code, notes, and snippets.

@eioo
Created May 27, 2019 11:11
Show Gist options
  • Save eioo/1a458153ec205a6458a5ce26459afa96 to your computer and use it in GitHub Desktop.
Save eioo/1a458153ec205a6458a5ce26459afa96 to your computer and use it in GitHub Desktop.
class Solution:
def simplifyPath(self, path: str) -> str:
current_path = []
path = path.replace('//', '/')
parts = list(filter(None, path.split('/')))
for part in parts:
if part == '.':
continue
elif part == '..':
current_path = current_path[:-1]
else:
current_path += [part]
return '/' + '/'.join(current_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment