本文主要是介绍224. Basic Calculator(Leetcode每日一题-2021.03.10)--抄答案,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Problem
Given a string s representing an expression, implement a basic calculator to evaluate it.
Constraints:
- 1 <= s.length <= 3 * 10^5
- s consists of digits, ‘+’, ‘-’, ‘(’, ‘)’, and ’ '.
- s represents a valid expression.
Example1
Input: s = “1 + 1”
Output: 2
Example2
Input: s = " 2-1 + 2 "
Output: 3
Example3
Input: s = “(1+(4+5+2)-3)+(6+8)”
Output: 23
Solution
class Solution {
public:void eval(stack<int> &num,stack<char> &op){auto b = num.top();num.pop();auto a = num.top();num.pop();
这篇关于224. Basic Calculator(Leetcode每日一题-2021.03.10)--抄答案的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!