跳至主要内容

1598. Crawler Log Folder

· 閱讀時間約 1 分鐘
class Solution {
public:
int minOperations(vector<string>& logs)
{
int depth = 0;
for (string log : logs)
{
if (log == "../")
{
depth = max(0, --depth);
}
else if (log != "./")
{
++depth;
}
}
return depth;
}
};
  • T: $O(n)$
  • S: $O(1)$