此题用C写起来估计还是很有难度的
class Solution:
def simplifyPath(self, path: str) -> str:
path = path.strip().split('/')
stack = []
for i in path:
if i == '..':
if len(stack) > 0:
stack.pop()
else:
continue
elif i == '.' or i == '':
continue
else:
stack.append(i)
print(stack)
return '/' + '/'.join(stack)
网友评论