224 Basic Calculator
Last updated
Was this helpful?
Last updated
Was this helpful?
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-negative integers and empty spaces.
You may assume that the given expression is always valid.
Some examples:
思路:这题输入的符号只有括号,加号,减号和数字,因为有括号,所以要运算优先级,括号里的表达式是一个整体,所以适合用stack做
时间和空间复杂度O(n)