Simplify Path
Given an absolute Unix-style file path, return its canonical form. Collapse repeated slashes into one, drop '.' (current directory), and let '..' move up one directory (ignored at the root). The canonical path starts with a single '/', has no trailing '/', and has exactly one '/' between components.
Open official problem prompt ↗Reduce a messy absolute path to its unique simplest equivalent form.
Walking through folders in a file browser: entering a folder is a push, clicking the 'up' button is a pop, and clicking the current folder ('.') does nothing.
- Input
- path = "/a/./b/../../c/"
- Output
- "/c"
- Why
- '.' is skipped, 'b' is entered then removed by the first '..', 'a' is removed by the second '..', leaving only 'c'.
1 <= path.length <= 3000path consists of English letters, digits, '.', '/' and '_'path is a valid absolute Unix path beginning with a single '/'