|
| 1 | +{ |
| 2 | + "problem_name": "basic_calculator", |
| 3 | + "solution_class_name": "Solution", |
| 4 | + "problem_number": "224", |
| 5 | + "problem_title": "Basic Calculator", |
| 6 | + "difficulty": "Hard", |
| 7 | + "topics": "Math, String, Stack, Recursion", |
| 8 | + "tags": ["grind-75"], |
| 9 | + "readme_description": "Given a string `s` representing a valid expression, implement a basic calculator to evaluate it, and return the result of the evaluation.\n\n**Note:** You are **not** allowed to use any built-in function which evaluates strings as mathematical expressions, such as `eval()`.", |
| 10 | + "readme_examples": [ |
| 11 | + { "content": "```\nInput: s = \"1 + 1\"\nOutput: 2\n```" }, |
| 12 | + { "content": "```\nInput: s = \" 2-1 + 2 \"\nOutput: 3\n```" }, |
| 13 | + { "content": "```\nInput: s = \"(1+(4+5+2)-3)+(6+8)\"\nOutput: 23\n```" } |
| 14 | + ], |
| 15 | + "readme_constraints": "- `1 <= s.length <= 3 * 10^5`\n- `s` consists of digits, `'+'`, `'-'`, `'('`, `')'`, and `' '`.\n- `s` represents a valid expression.\n- `'+'` is **not** used as a unary operation (i.e., `\"+1\"` and `\"+(2 + 3)\"` is invalid).\n- `'-'` could be used as a unary operation (i.e., `\"-1\"` and `\"-(2 + 3)\"` is valid).\n- There will be no two consecutive operators in the input.\n- Every number and running calculation will fit in a signed 32-bit integer.", |
| 16 | + "readme_additional": "", |
| 17 | + "solution_imports": "", |
| 18 | + "solution_methods": [ |
| 19 | + { "name": "calculate", "parameters": "s: str", "return_type": "int", "dummy_return": "0" } |
| 20 | + ], |
| 21 | + "test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import Solution", |
| 22 | + "test_class_name": "BasicCalculator", |
| 23 | + "test_helper_methods": [ |
| 24 | + { "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" } |
| 25 | + ], |
| 26 | + "test_methods": [ |
| 27 | + { |
| 28 | + "name": "test_calculate", |
| 29 | + "parametrize": "s, expected", |
| 30 | + "parametrize_typed": "s: str, expected: int", |
| 31 | + "test_cases": "[(\"1 + 1\", 2), (\" 2-1 + 2 \", 3), (\"(1+(4+5+2)-3)+(6+8)\", 23), (\"1\", 1), (\"-1\", -1), (\"-(1+2)\", -3), (\"2147483647\", 2147483647), (\"1-1+1\", 1)]", |
| 32 | + "body": "result = self.solution.calculate(s)\nassert result == expected" |
| 33 | + } |
| 34 | + ], |
| 35 | + "playground_imports": "from solution import Solution", |
| 36 | + "playground_test_case": "# Example test case\ns = '(1+(4+5+2)-3)+(6+8)'\nexpected = 23", |
| 37 | + "playground_execution": "result = Solution().calculate(s)\nresult", |
| 38 | + "playground_assertion": "assert result == expected" |
| 39 | +} |
0 commit comments