"""
You are building an educational website and want to create a simple calculator for students to use. The calculator will only allow addition and subtraction of non-negative integers.
We also want to allow parentheses in our input. Given an expression string using the "+", "-", "(", and ")" operators like "5+(16-2)", write a function to parse the string and evaluate the result.
Sample output:
calculate("5+16-((9-6)-(4-2))+1") => 21
calculate("22+(2-4)") => 20
calculate("6+9-12") => 3
calculate("((1024))") => 1024
calculate("1+(2+3)-(4-5)+6") => 13
calculate("255") => 255
n: length of the input string
"""
https://leetcode.com/problems/basic-calculator/
This is a follow up question, the first question is a caculator without "()", so, kind of easy to implement...
i am using RE to complete the first question < 10 mins i think... stuck at the above one...
i tried using stack, but looks too hard to me to implement those logic, i never done the above caculator leetocde problem yet. so, i come back to RE again, trying to find out '(x-x)', and use hashmap to store '(x-x)': y and use this replace back to the input, and keep find "()" and caculate and replace back, tyring to convert the input wihtout any "()", but times up...
this is kind of a phone screen to the hire company Roblox... still thinking of should i select the re-do, need to be confirm in 24 hrs. any suggestions?