---
# System prepended metadata

title: LeetCode 1598. Crawler Log Folder

---

# LeetCode 1598. Crawler Log Folder
[LeetCode 1598. Crawler Log Folder](https://leetcode.com/problems/crawler-log-folder/) (難度 通過率)
<!-- 
(<font color=#00AF9B>Easy</font> 53.8%) 
(<font color=#FFB800>Medium</font> 39.6%)
(<font color=#FF375F>Hard</font>)
 -->
    
- 限制 :

    <ul>
    <li><code>1 <= logs.length <= 10^3</code></li>
    <li><code>2 <= logs[i].length <= 10</code></li>
    <li><code>logs[i] contains lowercase English letters, digits, '.', and '/'.</code></li>
    <li><code>logs[i] follows the format described in the statement.</code></li>
    <li><code>Folder names consist of lowercase English letters and digits.</code></li>
    </ul>

- Solution
    - 時間複雜度: $O(n)$
    - 空間複雜度: $O(1)$

- 程式碼
    ```c++=
    class Solution {
    public:
        int minOperations(vector<string>& logs) {
            int result = 0;
            for (auto& log : logs) {
                if (log == "../" && result > 0)
                    result = result - 1;
                else if (log == "../" && result <= 0)
                    continue;
                else if (log == "./")
                    continue;
                else
                    result++;
            }
            return result;
        }
    };
    ```
</details>