|
| 1 | +<h2><a href="https://leetcode.com/problems/crawler-log-folder">1598. Crawler Log Folder</a></h2><h3>Easy</h3><hr><p>The Leetcode file system keeps a log each time some user performs a <em>change folder</em> operation.</p> |
| 2 | + |
| 3 | +<p>The operations are described below:</p> |
| 4 | + |
| 5 | +<ul> |
| 6 | + <li><code>"../"</code> : Move to the parent folder of the current folder. (If you are already in the main folder, <strong>remain in the same folder</strong>).</li> |
| 7 | + <li><code>"./"</code> : Remain in the same folder.</li> |
| 8 | + <li><code>"x/"</code> : Move to the child folder named <code>x</code> (This folder is <strong>guaranteed to always exist</strong>).</li> |
| 9 | +</ul> |
| 10 | + |
| 11 | +<p>You are given a list of strings <code>logs</code> where <code>logs[i]</code> is the operation performed by the user at the <code>i<sup>th</sup></code> step.</p> |
| 12 | + |
| 13 | +<p>The file system starts in the main folder, then the operations in <code>logs</code> are performed.</p> |
| 14 | + |
| 15 | +<p>Return <em>the minimum number of operations needed to go back to the main folder after the change folder operations.</em></p> |
| 16 | + |
| 17 | +<p> </p> |
| 18 | +<p><strong class="example">Example 1:</strong></p> |
| 19 | + |
| 20 | +<p><img alt="" src="https://assets.leetcode.com/uploads/2020/09/09/sample_11_1957.png" style="width: 775px; height: 151px;" /></p> |
| 21 | + |
| 22 | +<pre> |
| 23 | +<strong>Input:</strong> logs = ["d1/","d2/","../","d21/","./"] |
| 24 | +<strong>Output:</strong> 2 |
| 25 | +<strong>Explanation: </strong>Use this change folder operation "../" 2 times and go back to the main folder. |
| 26 | +</pre> |
| 27 | + |
| 28 | +<p><strong class="example">Example 2:</strong></p> |
| 29 | + |
| 30 | +<p><img alt="" src="https://assets.leetcode.com/uploads/2020/09/09/sample_22_1957.png" style="width: 600px; height: 270px;" /></p> |
| 31 | + |
| 32 | +<pre> |
| 33 | +<strong>Input:</strong> logs = ["d1/","d2/","./","d3/","../","d31/"] |
| 34 | +<strong>Output:</strong> 3 |
| 35 | +</pre> |
| 36 | + |
| 37 | +<p><strong class="example">Example 3:</strong></p> |
| 38 | + |
| 39 | +<pre> |
| 40 | +<strong>Input:</strong> logs = ["d1/","../","../","../"] |
| 41 | +<strong>Output:</strong> 0 |
| 42 | +</pre> |
| 43 | + |
| 44 | +<p> </p> |
| 45 | +<p><strong>Constraints:</strong></p> |
| 46 | + |
| 47 | +<ul> |
| 48 | + <li><code>1 <= logs.length <= 10<sup>3</sup></code></li> |
| 49 | + <li><code>2 <= logs[i].length <= 10</code></li> |
| 50 | + <li><code>logs[i]</code> contains lowercase English letters, digits, <code>'.'</code>, and <code>'/'</code>.</li> |
| 51 | + <li><code>logs[i]</code> follows the format described in the statement.</li> |
| 52 | + <li>Folder names consist of lowercase English letters and digits.</li> |
| 53 | +</ul> |
0 commit comments