Basic Calculator
Implement a basic calculator to evaluate a simple expression string.
The expression string may contain open(and closing parentheses), the plus+or minus sign-,non-negativeintegers and empty spaces.
Example 1:
Input:
"1 + 1"
Output:
2Example 2:
Input:
" 2-1 + 2 "
Output:
3Example 3:
Input:
"(1+(4+5+2)-3)+(6+8)"
Output:
23分析
带括号,所以每次相乘带sign,遇到括号把+1/-1sign压入,再压入前面result。遇到)就弹出站
Last updated
Was this helpful?