package leetcode;

/**
 * https://leetcode.com/problems/crawler-log-folder/
 */
public class Problem1598 {
    public int minOperations(String[] logs) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1598 prob = new Problem1598();
        System.out.println(prob.minOperations(new String[]{"d1/","d2/","../","d21/","./"})); // 2
        System.out.println(prob.minOperations(new String[]{"d1/","d2/","./","d3/","../","d31/"})); // 3
        System.out.println(prob.minOperations(new String[]{"d1/","../","../","../"})); // 0
    }
}

@@ -12,16 +12,41 @@
 tcode;%0A%0A
+import java.util.Stack;%0A%0A
 /**%0A * h
@@ -183,425 +183,408 @@
     
-// TODO%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem1598 prob = new Problem1598();%0A        System.out.println(prob.minOperations(new String%5B%5D%7B%22d1/%22,%22d2/%22,%22../%22,%22d21/%22,%22./%22%7D)); // 2%0A        System.out.println(prob.minOperations(new String%5B%5D%7B%22d1/%22,%22d2/%22,%22./%22,%22d3/%22,%22../%22,%22d31/%22%7D)); // 3%0A        System.out.println(prob.minOperations(new String%5B%5D%7B%22d1/%22,%22../%22,%22../%22,%22../%22%7D)); // 0
+Stack%3CString%3E stack = new Stack%3C%3E();%0A        for (String log : logs) %7B%0A            if (log.equals(%22../%22)) %7B%0A                if (!stack.isEmpty()) %7B%0A                    stack.pop();%0A                %7D%0A            %7D else if (log.equals(%22./%22)) %7B%0A                // Do nothing.%0A            %7D else %7B%0A                stack.add(log);%0A            %7D%0A        %7D%0A        return stack.isEmpty() ? 0 : stack.size();
 %0A   

Solve problem 1598