package leetcode;

/**
 * https://leetcode.com/problems/clumsy-factorial/
 */
public class Problem1006 {
    public int clumsy(int N) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1006 prob = new Problem1006();
        System.out.println(prob.clumsy(4)); // 7
        System.out.println(prob.clumsy(10)); // 12
    }
}

@@ -12,16 +12,41 @@
 tcode;%0A%0A
+import java.util.Stack;%0A%0A
 /**%0A * h
@@ -166,32 +166,1122 @@
     
-// TODO%0A        return 0
+char%5B%5D ops = new char%5B%5D%7B'*', '/', '+', '-'%7D;%0A        int opIdx = 0;%0A        Stack%3CInteger%3E numbers = new Stack%3C%3E();%0A        Stack%3CCharacter%3E operators = new Stack%3C%3E();%0A        for (int i = N; i %3E= 1; i--) %7B%0A            if (i == N) %7B%0A                numbers.add(i);%0A                continue;%0A            %7D%0A            char op = ops%5BopIdx%5D;%0A            while (!operators.isEmpty() &&%0A                ((op != '*' && op != '/') %7C%7C (operators.peek() != '+' && operators.peek() != '-'))) %7B%0A                numbers.push(apply(numbers.pop(), numbers.pop(), operators.pop()));%0A            %7D%0A            numbers.add(i);%0A            operators.add(op);%0A            opIdx = (opIdx + 1) %25 ops.length;%0A        %7D%0A        while (!operators.isEmpty()) %7B%0A            numbers.push(apply(numbers.pop(), numbers.pop(), operators.pop()));%0A        %7D%0A        return numbers.pop();%0A    %7D%0A%0A    private static int apply(int b, int a, char op) %7B%0A        if (op == '*') %7B%0A            return a * b;%0A        %7D else if (op == '/') %7B%0A            return a / b;%0A        %7D else if (op == '+') %7B%0A            return a + b;%0A        %7D%0A        return a - b
 ;%0A  

Update problem 1006