miglss

47.YA

May 24th, 2025
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.41 KB | None | 0 0
  1. class Solution:
  2.     def simplifyPath(self, path: str) -> str:
  3.         deslashed = path.split('/')
  4.         stack = []
  5.  
  6.         for s in deslashed:
  7.             if s == '.':
  8.                 continue
  9.             elif s == '..':
  10.                 if len(stack) > 0:
  11.                     stack.pop()
  12.             elif s != '':
  13.                 stack.append(s)
  14.        
  15.         return "/" + "/".join(stack)
  16.            
Advertisement
Add Comment
Please, Sign In to add comment