Basic Calculator

Given a string s representing a valid expression, implement a basic calculator to evaluate it,and return the result of the evaluation.
Note: You are not allowed to use any built-in function which evaluates strings as mathematical expressions, such as eval().
        
       Input:-2-1 + 2
       Input Description: Given a string s representing a valid expression. 
       Output: 3
       Output Description: return the result of the evaluation. 
       Constraints: 1 <= s.length <= 3 * 105 s consists of digits, '+', '-', '(', ')', and ' '. s represents a valid expression. '+' is not used as a unary operation. '-' could be used as a unary operation. There will be no two consecutive operators in the input. Every numb...
       Explanation: null

Loading...