Advertisement
1598. Crawler Log Folder
EasyView on LeetCode
Time: O(n)
Space: O(1)
Approach
Simulate directory depth: '../' decrements, './' stays, otherwise increment; clamp at 0.
1598.cs
C#
// Approach: Simulate directory depth: '../' decrements, './' stays, otherwise increment; clamp at 0.
// Time: O(n) Space: O(1)
public class Solution
{
public int MinOperations(string[] logs)
{
int ops = 0;
foreach (string log in logs)
{
if (log == "./")
continue;
if (log == "../")
{
if (ops > 0)
ops--;
}
else
ops++;
}
return ops;
}
}Advertisement
Was this solution helpful?