Created
May 27, 2019 11:11
-
-
Save eioo/1a458153ec205a6458a5ce26459afa96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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