Simplify Path
path is an absolute file path that starts with /. Simplify it:
.means the current folder and is ignored...means go up one folder (at the root it does nothing).- Several slashes in a row count as one.
Return the simplified path: it starts with /, folder names are separated by a single /, and there is no trailing / (except for the root path / itself).
Example 1
path "/home//foo/"
returns "/home/foo"
/home/foo.
Example 2
path "/a/./b/../../c/"
returns "/c"
Goes into a, b, back out twice, then c: /c.
Constraints
1 <= len(path) <= 100- Names use letters, digits,
.and_; the path always starts with/
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.