Skip to main content
Back to problems
#1598
Easy Algorithms

Crawler log folder

Array String Stack
71.6% acceptance
Feb 25, 2026
1542
99
The Leetcode file system keeps a log each time some user performs a change folder operation. "../" : Move to the parent folder. "./" : Remain in the same folder. "x/" : Move to child folder x. Return the minimum number of operations needed to go back to the main folder after the change folder operations.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn min_operations(logs: Vec<String>) -> i32 {
    let mut depth = 0;
    for log in &logs {
      if log == "../" {
        if depth > 0 { depth -= 1; }
      } else if log != "./" {
        depth += 1;
      }
    }
    depth
  }
}