Size: 351 bytes.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#!/usr/bin/env python3
# cs/q/simplify_path/simplify_path.py
def SimplifyPath(s: str) -> str:
    stack = []
    for comp in s.split("/"):
        if comp == "" or comp == ".":
            continue
        if comp == "..":
            if stack:
                stack.pop()
        else:
            stack.append(comp)
    return "/" + "/".join(stack)
v0 (commit) © 2025 @p13i.io | Load balancer proxied to: cs-code-viewer-3:8080 in 2ms.