18. Canonical Path
Easy
Normalize an absolute Unix path and return its canonical form. Repeated slashes and . components do not change the path; .. moves up one level, without going above the root. The result does not end with a slash, except when it is the root itself.
Example 1
Input: caminho = "/time//ana/../bia/"
Output: "/time/bia"
Explanation: Repeated slashes are collapsed and `..` removes `ana`.
Example 2
Input: caminho = "/../../"
Output: "/"
Constraints
- 1 <= caminho.length <= 3000
- `caminho` starts with `/` and contains letters, `.`, `..` and `/`.
StringsStack
Saved in this browser
Caso 1
caminho =
"/time//ana/../bia/"
Expected =
"/time/bia"
Caso 2
caminho =
"/../../"
Expected =
"/"
Run checks these 2 cases. Submit runs all 6, including hidden ones.