题解 | #简化目录路径#
简化目录路径
https://www.nowcoder.com/practice/3177bcbfd947409ba833efb5a5b4a24c
#
class Solution:
def simplifyPath(self , path: str) -> str:
# write code here
dirs = path.split('/')
new_path = []
for i in dirs:
if i=='..' and new_path:
new_path.pop()
elif i and i != '.' and i != '..':
new_path.append(i)
return '/'+'/'.join(new_path)
查看5道真题和解析