Skip to content

Instantly share code, notes, and snippets.

@rohith2506
Created November 24, 2014 09:59
Show Gist options
  • Save rohith2506/8f47759e7f6200d149c8 to your computer and use it in GitHub Desktop.
Save rohith2506/8f47759e7f6200d149c8 to your computer and use it in GitHub Desktop.
class Solution:
# @param path, a string
# @return a string
def simplifyPath(self, path):
result = []
pathList = path.split('/')
for content in pathList:
if content:
if content == '..':
try:
result.pop()
except:
result = []
elif content != '.':
result.append(content)
return '/'+'/'.join(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment