71. Simplify Path
Practice Simplify Path for free on NudgeCode: Medium, Stack pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Given an absolute Unix-style file path (starting with /), return its simplified canonical form.
.means the current directory and..means the parent directory (..at the root stays at the root)- repeated slashes like
//count as one/ - any other name, including
..., is a normal directory name
The result starts with a single /, separates names with one /, and has no trailing / (except the root itself, "/").
Example
path = "/a/./b/../../c/" -> "/c"
Constraints
- 1 <= path.length <= 3000
pathhas letters, digits,.,/and_, and starts with/