public class Solution {
    public int calculate(String s) {
        StringBuilder stringBuilder = new StringBuilder();
        int result = 0, start = 0, op = '+';
        while (start <= s.length()) {
            if (start == s.length() || (s.charAt(start) == '+' || s.charAt(start) == '-')) {
                if (op == '+') result += this.calc(stringBuilder);
                if (op == '-') result -= this.calc(stringBuilder);
                if (start != s.length()) op = s.charAt(start);
                stringBuilder = new StringBuilder();
            } else {
                if (s.charAt(start) != ' ') stringBuilder.append(s.charAt(start));
            }
            start++;
        }
        return result;
    }

    private int calc(StringBuilder sb) {
        int result = 1, op = '*', tmp = 0;
        for (int i = 0; i <= sb.length(); i++) {
            if (i == sb.length() || sb.charAt(i) == '*' || sb.charAt(i) == '/') {
                if (op == '*') result *= tmp;
                if (op == '/') result /= tmp;
                if (i != sb.length()) op = sb.charAt(i);
                tmp = 0;
            } else {
                tmp = tmp * 10 + sb.charAt(i) - 48;
            }
        }
        return result;
    }
}

@@ -1,12 +1,37 @@
+import java.util.Stack;%0A%0A
 public class
@@ -93,53 +93,40 @@
   St
-ringBuild
+ack%3CInteg
 er
+%3E
  st
-ringBuilder = new StringBuilder
+ack = new Stack%3C%3E
 ();%0A
@@ -140,20 +140,8 @@
  int
- result = 0,
  sta
@@ -156,16 +156,25 @@
 op = '+'
+, tmp = 0
 ;%0A      
@@ -244,17 +244,16 @@
 th() %7C%7C 
-(
 s.charAt
@@ -292,17 +292,68 @@
 ) == '-'
-)
+ %7C%7C s.charAt(start) == '*' %7C%7C s.charAt(start) == '/'
 ) %7B%0A    
@@ -383,41 +383,22 @@
 +') 
-result += this.calc(stringBuilder
+stack.push(tmp
 );%0A 
@@ -431,160 +431,152 @@
 -') 
-result -= this.calc(stringBuilder);%0A                if (start != s.length()) op = s.charAt(start);%0A                stringBuilder = new StringBuilder();%0A
+stack.push(-tmp);%0A                if (op == '*') stack.push(stack.pop() * tmp);%0A                if (op == '/') stack.push(stack.pop() / tmp);%0A  
     
@@ -579,32 +579,34 @@
             
-%7D else %7B
+  tmp = 0;
 %0A           
@@ -617,54 +617,35 @@
  if 
-(s.charAt
 (start
-)
  != 
-' ') stringBuilder.append(
+s.length()) op = 
 s.ch
@@ -655,17 +655,16 @@
 t(start)
-)
 ;%0A      
@@ -674,284 +674,99 @@
    %7D
-%0A            start++;%0A        %7D%0A        return result;%0A    %7D%0A%0A    private int calc(StringBuilder sb) %7B%0A        int result = 1, op = '*', tmp = 0;%0A        for (int i = 0; i %3C= sb.length(); i++) %7B%0A            if (i == sb.length() %7C%7C sb.charAt(i) == '*' %7C%7C sb.charAt(i) == '/') %7B
+ else %7B%0A                if (s.charAt(start) != ' ') tmp = tmp * 10 + s.charAt(start) - '0';
 %0A   
@@ -778,40 +778,29 @@
     
+%7D%0A
     
-if (op == '*') result *= tmp
+        start++
 ;%0A  
@@ -797,32 +797,35 @@
 tart++;%0A        
+%7D%0A%0A
         if (op =
@@ -821,29 +821,18 @@
    i
-f (op == '/')
+nt
  result 
 /= t
@@ -831,14 +831,11 @@
 ult 
-/
 = 
-tmp
+0
 ;%0A  
@@ -844,178 +844,40 @@
     
-        if (i != sb.length()) op = sb.charAt(i);%0A                tmp = 0;%0A            %7D else %7B%0A                tmp = tmp * 10 + sb.charAt(i) - 48;%0A            %7D%0A        %7D
+for (int i : stack) result += i;
 %0A   

optimize using stack