class Solution:
# @param path, a string
# @return a string
def simplifyPath(self, path):
stack=[]
pathlist=path.split('/')
for i in pathlist:
if i==''or i=='.':
continue
elif i=='..':
if len(stack)>=1:
stack.pop()
else:
stack.append(i)
rst='/'+'/'.join(stack)
if rst=='':
return '/'
return rst
Friday, September 19, 2014
Leetcode: Simplify Path @Python
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment