@@ -0,0 +1,1897 @@
+package leetcode;%0A%0Aimport java.util.Stack;%0A%0A/**%0A * https://leetcode.com/problems/basic-calculator/%0A */%0Apublic class Problem224 %7B%0A    public int calculate(String s) %7B%0A        String str = s.replaceAll(%22%5C%5Cs+%22, %22%22);%0A        Stack%3CInteger%3E operands = new Stack%3C%3E();%0A        Stack%3CCharacter%3E operators = new Stack%3C%3E();%0A        String num = %22%22;%0A        for (char c : str.toCharArray()) %7B%0A            if (Character.isDigit(c)) %7B%0A                num += c;%0A            %7D else if (c == '+' %7C%7C c == '-') %7B%0A                if (!num.isEmpty()) %7B%0A                    operands.add(Integer.parseInt(num));%0A                    num = %22%22;%0A                %7D%0A                if (!operators.isEmpty()) %7B%0A                    evaluate(operands, operators);%0A                %7D%0A                operators.add(c);%0A            %7D else if (c == '(') %7B%0A                operators.add(c);%0A            %7D else if (c == ')') %7B%0A                if (!num.isEmpty()) %7B%0A                    operands.add(Integer.parseInt(num));%0A                    num = %22%22;%0A                %7D%0A                if (!operators.isEmpty()) %7B%0A                    evaluate(operands, operators);%0A                %7D%0A            %7D%0A        %7D%0A        if (!num.isEmpty()) %7B%0A            operands.add(Integer.parseInt(num));%0A            num = %22%22;%0A        %7D%0A        if (!operators.isEmpty()) %7B%0A            evaluate(operands, operators);%0A        %7D%0A        return operands.pop();%0A    %7D%0A    %0A    private void evaluate(Stack%3CInteger%3E operands, Stack%3CCharacter%3E operators) %7B%0A        char op = operators.pop();%0A        if (op == '(') %7B%0A            return;%0A        %7D%0A        int a = operands.pop();%0A        int b = operands.pop();%0A        int val = evaluate(b, a, op);%0A        operands.add(val);%0A    %7D%0A    %0A    private int evaluate(int a, int b, char op) %7B%0A        if (op == '+') %7B%0A            return a + b;%0A        %7D else %7B // op == '-'%0A            return a - b;%0A        %7D%0A    %7D%0A%7D%0A

Solve problem 224