71 Simplify Path – Medium
Problem:
Given an absolute path for a file (Unix-style), simplify it.
For example, path = "/home/", => "/home" path = "/a/./b/../../c/", => "/c"
Thoughts:
This is a good example to use stack. Split input string by “/”, then iterate over the string array.
If it’s empty or “.”, don’t do anything. If it’s “..”, pop one element. Otherwise, put the part into the stack.
Solutions:
Last updated