71. Simplify Path
All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : June 11, 2024
Last updated : July 01, 2024
Related Topics : String, Stack
Acceptance Rate : 45.57 %
class Solution:
def simplifyPath(self, path: str) -> str:
output = deque()
temp = path.replace('//', '/')
while '//' in temp :
temp = temp.replace('//', '/')
temp = temp.split('/')
for folder in temp :
if folder == '.' :
continue
if folder == '..' :
if len(output) > 0 :
output.pop()
continue
output.append(folder)
while len(output) > 0 and output[0] == '' :
output.popleft()
while len(output) > 0 and output[-1] == '' :
output.pop()
return '/' + '/'.join(output)