423. Folder Depth
A file explorer records every navigation click as a string. "x/" opens the child folder named x, which always exists. "../" moves up to the parent folder, and does nothing if you are already in the root folder. "./" stays in the current folder. You always start in the root.
Given the list logs of clicks in the order they happened, return the minimum number of "../" clicks that would bring you back to the root folder from where you ended up.
Example 1
- Input:
- logs = ["a/","b/","../","./","cd/","e1/"]
- Output:
- 3
- Explanation:
The path grows a, a/b, back to a, stays, then a/cd and a/cd/e1: three levels deep, so three clicks go back to the root.
Example 2
- Input:
- logs = ["../","../","m/","../","../","k7/"]
- Output:
- 1
- Explanation:
Going up from the root changes nothing. The path becomes m, then root again, root again, then k7: depth 1.
Constraints
1 ≤ logs.length ≤ 1000
Each entry is "../", "./", or a folder name of 1 to 10 lower-case letters or digits followed by "/".
How this problem is judged
- Answers
- Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
Expected complexity
- Time
- O(n)
- Space
- O(1)