Loading
Leetcode / 1598. Crawler Log Folder

Pick a programming language:

Here is the source code for the solution to this problem.

class Solution {
    public int minOperations(String[] logs) {
        int level = 0;

        for (int i = 0; i < logs.length; i++) {
            if (logs[i].equals("./")) {
                // do nothing
            }
            else if (logs[i].equals("../")) {
                if (level > 0) {
                    level--;
                }
            }
            else {
                // going down a folder
                level++;
            }
        }

        return level;
    }
}
Did you like the lesson? 😆👍
Consider a donation to support our work: