Implement a Calculator class that performs basic arithmetic operations on a running result.
The Calculator class should support the following operations:
Calculator(initialValue) — Initialize the calculator with the given initialValue.add(n) — Add n to the current result.subtract(n) — Subtract n from the current result.multiply(n) — Multiply the current result by n.divide(n) — Divide the current result by n using integer division (truncate toward zero). If n is 0, do nothing.getResult() — Return the current result.reset() — Reset the result back to the initialValue.["Calculator","add","multiply","getResult","subtract","divide","getResult","reset","getResult"]
[[10],[5],[2],[],[7],[3],[],[],[]][null,null,null,30,null,null,7,null,10]-10000 <= initialValue, n <= 10000At most 1000 calls will be made to add, subtract, multiply, divide, getResult, and resetDivision by zero should be ignored (result unchanged)Division truncates toward zero (e.g., 7/2=3, -7/2=-3)Run your code to see results
Use Cmd+Enter to run