LC 224 - Basic Calculator
Approach This problem is not hard but need to consider some special conditions. I found that actually we just need to trace the actual sign after removing the parantheses. For instance, 1-(2-(3+4)) is equal to 1-2+3+4, so we need to buffer the current actual sign when we get the (. In this case, we stack - when getting the first (, and when approaching the second (, we know that it is negative outside, and this is negative so we need to invert the sign inside this parantheses, so stack + inside. And the sign is removed after ) is encountered. ...