Description
The Leetcode file system logs folder changes. "../" moves to parent, "./" stays in current, "x/" moves to child x. Return minimum operations to return to main folder.
Examples
Input:
logs = ["d1/","d2/","../","d21/","./"]Output:
2Explanation:
2 '../' to return.
Input:
logs = ["../","./","d3/","d4/","../","d5/"]Output:
2Explanation:
Start at main folder (0). '../' at main stays at 0. './' stays at 0. 'd3/' goes to depth 1. 'd4/' goes to depth 2. '../' goes back to depth 1. 'd5/' goes to depth 2. Final depth is 2.
Input:
logs = ["d1/","d2/","d3/","../","../","../"]Output:
0Explanation:
Start at main folder (0). 'd1/' goes to depth 1. 'd2/' goes to depth 2. 'd3/' goes to depth 3. First '../' goes to depth 2. Second '../' goes to depth 1. Third '../' goes to depth 0 (main folder). Final depth is 0.
Constraints
- •
1 ≤ logs.length ≤ 10³