Evaluate the value of an arithmetic expression in .
Valid operators are +
, -
, *
, /
. Each operand may be an integer or another expression.
Some examples:
["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9 ["4", "13", "5", "/", "+"] -> (4 + (13 / 5)) -> 6
思考:注意负数。
class Solution {public: int stoi(string str) { bool flag=true; if(str[0]=='-') flag=false; int ret=0,i; i=(flag)?0:1; for(;i&tokens) { int ans=0; stack s; int a,b,c; for(int i=0;i