pytudes._2021.leetcode.hard._224_basic_calculator

https://leetcode.com/problems/basic-calculator/

Constraints:
  • 1 ≤ s.length ≤ 3 * 10^5

  • s consists of digits, ‘+’, ‘-’, ‘(’, ‘)’, and ‘ ‘

  • s represents a valid expression

Examples:
>>> Solution().calculate("0")
0

Module Contents

Classes

Solution

Functions

calculate_via_rpn(expression)

Return the evaluation of the given infix arithmetic expression

class pytudes._2021.leetcode.hard._224_basic_calculator.Solution[source]
calculate(s)[source]
Parameters:

s (str) –

Return type:

int

pytudes._2021.leetcode.hard._224_basic_calculator.calculate_via_rpn(expression)[source]

Return the evaluation of the given infix arithmetic expression

Args:

expression: A valid infix arithmetic expression containing only numbers from R and symbols in ‘+’, ‘-’, ‘(’, ‘)’, and ‘ ‘

Examples:
>>> calculate_via_rpn("1 + 1")
2
>>> calculate_via_rpn(" 2-1 + 2 ")
3
>>> calculate_via_rpn("(1+(4+5+2)-3)+(6+8)")
23
See Also:
Parameters:

expression (str) –

Return type:

int