1598. Crawler Log Folder
All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : July 10, 2024
Last updated : July 10, 2024
Related Topics : Array, String, Stack
Acceptance Rate : 71.76 %
/**
* @param {string[]} logs
* @return {number}
*/
var minOperations = function(logs) {
const stk = [];
logs.forEach(el => {
switch (el) {
case './' :
break;
case '../' :
stk.pop();
break;
default :
stk.push(el);
break;
}
});
return stk.length;
};
/**
* @param {string[]} logs
* @return {number}
*/
var minOperations = function(logs) {
var counter = 0;
logs.forEach(el => {
switch (el) {
case './' :
break;
case '../' :
if (counter > 0)
counter--;
break;
default :
counter++;
break;
}
});
return counter;
};
int minOperations(char** logs, int logsSize) {
int counter = 0;
for (int i = 0; i < logsSize; i++) {
if (logs[i][0] != '.') {
counter++;
} else if (strcmp(logs[i], "../") == 0 && counter > 0) {
counter--;
}
}
return counter;
}