227. Basic Calculator II
# Medium
key idea: stack
Search the operator then number
1) if the operator is "+", push the number to the stack;
2) if the operator is "-", push the opposite number to the stack;
3) if the operator is "*", pop the top number out to do calculate, then push back;
4) if the operator is "/", pop the top number out to do calculate, then push back. In python, "//" must distinguish negative and positive number.
In Python, 1//-10 = -1, because Python is "floor division", but the result we want is 0, so we can do int(1/-10) = 0
Last updated