@@ -0,0 +1,1955 @@
+public class Solution %7B%0A    public int calculate(String s) %7B%0A        Stack%3CInteger%3E st = new Stack%3CInteger%3E();%0A        %0A        s = s.replace(%22 %22, %22%22);%0A        %0A        for(int i = 0; i %3C s.length(); i ++)%7B%0A            if(s.charAt(i) == '(')%7B%0A                st.push(i);%0A            %7Delse if(s.charAt(i) == ')')%7B%0A                if(st.peek() == null)%7B%0A                    return 0;%0A                %7D%0A                int tmp = calWoParen(s.substring(st.peek()+1, i));%0A                if(tmp %3E= 0)%7B%0A                    s = s.substring(0, st.peek()) + tmp + s.substring(i+1);%0A                %7Delse%7B%0A                    if(st.peek() %3E= 1 && s.charAt(st.peek()-1) == '-')%7B%0A                        s = s.substring(0, st.peek()) +%220+%22 + Math.abs(tmp) + s.substring(i+1);%0A                    %7Delse%7B%0A                        s = s.substring(0, st.peek()) +%220%22 + tmp + s.substring(i+1);%0A                    %7D%0A                %7D%0A                i = st.pop()-1;%0A            %7D%0A        %7D%0A        return calWoParen(s);%0A    %7D%0A    %0A    private int calWoParen(String s)%7B%0A        int result = 0, operator = 0;%0A        String num = %22%22;%0A        for(int i = 0; i %3C s.length(); i ++)%7B%0A            if(!num.equals(%22%22) && !Character.isDigit(s.charAt(i)))%7B%0A                if(operator == 0)%7B%0A                    result += Integer.parseInt(num);%0A                %7Delse%7B%0A                    result -= Integer.parseInt(num);%0A                %7D%0A                num = %22%22;%0A            %7D%0A            if(s.charAt(i) == '+')%7B%0A                operator = 0;%0A            %7Delse if(s.charAt(i) == '-')%7B%0A                operator = 1;%0A            %7Delse if(Character.isDigit(s.charAt(i)))%7B%0A                num += s.charAt(i);%0A            %7D%0A        %7D%0A        if(!num.equals(%22%22))%7B%0A            if(operator == 0)%7B%0A                result += Integer.parseInt(num);%0A            %7Delse%7B%0A                result -= Integer.parseInt(num);%0A            %7D%0A            num = %22%22;%0A        %7D%0A        return result;%0A    %7D%0A%7D

Q224 Basic Calculator