| | 1 | | // -------------------------------------------------------------------------------- |
| | 2 | | // Copyright (C) 2025 Eugene Eremeev (also known as Yevhenii Yeriemeieiv). |
| | 3 | | // All Rights Reserved. |
| | 4 | | // -------------------------------------------------------------------------------- |
| | 5 | | // This software is the confidential and proprietary information of Eugene Eremeev |
| | 6 | | // (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not |
| | 7 | | // disclose such Confidential Information and shall use it only in accordance with |
| | 8 | | // the terms of the license agreement you entered into with Eugene Eremeev (also |
| | 9 | | // known as Yevhenii Yeriemeieiv). |
| | 10 | | // -------------------------------------------------------------------------------- |
| | 11 | |
|
| | 12 | | namespace LeetCode.Algorithms.CrawlerLogFolder; |
| | 13 | |
|
| | 14 | | /// <inheritdoc /> |
| | 15 | | public class CrawlerLogFolderSimulation : ICrawlerLogFolder |
| | 16 | | { |
| | 17 | | private const string MoveToParent = "../"; |
| | 18 | | private const string Remain = "./"; |
| | 19 | |
|
| | 20 | | /// <summary> |
| | 21 | | /// Time complexity - O(n) |
| | 22 | | /// Space complexity - O(1) |
| | 23 | | /// </summary> |
| | 24 | | /// <param name="logs"></param> |
| | 25 | | /// <returns></returns> |
| | 26 | | public int MinOperations(string[] logs) |
| 3 | 27 | | { |
| 3 | 28 | | var depth = 0; |
| | 29 | |
|
| 39 | 30 | | foreach (var log in logs) |
| 15 | 31 | | { |
| 15 | 32 | | switch (log) |
| | 33 | | { |
| | 34 | | case MoveToParent: |
| 5 | 35 | | depth = Math.Max(0, depth - 1); |
| 5 | 36 | | break; |
| | 37 | | case Remain: |
| 2 | 38 | | break; |
| | 39 | | default: |
| 8 | 40 | | depth++; |
| 8 | 41 | | break; |
| | 42 | | } |
| 15 | 43 | | } |
| | 44 | |
|
| 3 | 45 | | return depth; |
| 3 | 46 | | } |
| | 47 | | } |