1598. Crawler Log Folder
Easy
The Leetcode file system keeps a log each time some user performs a change folder operation.
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 ith step.
The file system starts in the main folder, then the operations in logs are performed.
Return the 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
以上是Crawler Log Folder的详细内容。更多信息请关注PHP中文网其他相关文章!