224 Basic Calculator
224. Basic Calculator
1. Question
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:
2. Implementation
思路:这题输入的符号只有括号,加号,减号和数字,因为有括号,所以要运算优先级,括号里的表达式是一个整体,所以适合用stack做
3. Time & Space Complexity
时间和空间复杂度O(n)
Last updated