1598. Crawler Log Folder
Easy
The Leetcode file system keeps a log each time some user performs achange folderoperation.
The operations are described below:
You are given a list of strings logs where logs[i] is the operation performed by the user at the ithstep.
The file system starts in the main folder, then the operations in logs are performed.
Returnthe minimum number of operations needed to go back to the main folder after the change folder operations.
Example 1:
Example 2:
Example 3:
Constraints:
Solution:
class Solution { /** * @param String[] $logs * @return Integer */ function minOperations($logs) { $depth = 0; foreach ($logs as $log) { if ($log == "../") { if ($depth > 0) { $depth--; } } elseif ($log != "./") { $depth++; } } return $depth; } }Contact Links
The above is the detailed content of Crawler Log Folder. For more information, please follow other related articles on the PHP Chinese website!