-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsolution.cpp
22 lines (22 loc) · 864 Bytes
/
solution.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Solution
{
public:
int minOperations(vector<string> &logs)
{
int depth = 0; // Initialize depth to 0, representing the root directory
for (const string &log : logs)
{ // Iterate over each log in the logs vector
if (log == "../")
{ // If the log is "../", move one level up
if (depth > 0)
depth--; // Only move up if depth is greater than 0
}
else if (log != "./")
{ // If the log is not "./", move one level down
depth++; // Increase depth to represent moving into a subdirectory
}
// No action is needed for "./" since it represents staying in the current directory
}
return depth; // Return the final depth, representing the folder level from the root
}
};