Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def simplifyPath(self, path: str) -> str:
- stack = []
- running_string = ""
- for c in path + "/":
- if c == "/":
- if running_string == ".." and len(stack) > 0:
- stack.pop()
- if running_string not in [".", "", ".."]:
- stack.append(running_string)
- running_string = ""
- else:
- running_string += c
- return "/" + "/".join(stack)
- class Solution:
- def simplifyPath(self, path: str) -> str:
- stack = []
- for part in path.split("/"):
- if part == "..":
- if stack:
- stack.pop()
- elif part not in [".", ""]:
- stack.append(part)
- return "/" + "/".join(stack)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement