运用栈简化路径
简化路径
https://www.nowcoder.com/practice/393e5a246a7546d1b2e4d7719647b7d9
#
#
# @param path string字符串
# @return string字符串
#
class Solution:
def simplifyPath(self , path ):
# write code here
stack=[]
parts = path.split('/')
for part in parts:
if part == '..' :
if stack:
stack.pop()
elif part =='.'or part == '':
continue
else:
stack.append(part)
return '/'+'/'.join(stack)
