Skip to content

Latest commit

 

History

History
95 lines (79 loc) · 1.89 KB

_1598. Crawler Log Folder.md

File metadata and controls

95 lines (79 loc) · 1.89 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : July 10, 2024

Last updated : July 10, 2024


Related Topics : Array, String, Stack

Acceptance Rate : 71.76 %


Solutions

JavaScript

/**
 * @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;
};

C

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;
}