Description
Given a Unix-style absolute file path, simplify it. Convert path like "/a/./b/../../c/" to canonical path "/c".
Examples
Input:
path = "/home//foo/"Output:
"/home/foo"Explanation:
Remove extra slashes.
Input:
path = "/a/./b/../../c/"Output:
/cExplanation:
Process directory navigation: '/a' enters directory a, './b' enters directory b (. means current directory), '../..' goes back two directories (out of b, then out of a, back to root), then '/c/' enters directory c.
Input:
path = "/a/b/c/../../../"Output:
/Explanation:
Start at root, navigate to /a/b/c, then use '../../../' to go back three directories: first '..' goes from c to b, second '..' goes from b to a, third '..' goes from a back to root directory.
Constraints
- •
1 ≤ path.length ≤ 3000