#2806

Account Balance After Rounded Purchase

pupil · 415 · lc easy +25 · 56.3% accepted · 292 likes · top 50%

Description

You start with a bank balance of 100 dollars.

An integer purchaseAmount is given, representing the price of a purchase. Before deducting, round purchaseAmount to the nearest multiple of 10 (call it roundedAmount), then subtract roundedAmount from your balance.

Return your remaining balance after the purchase.

Notes:

- 0 is a valid multiple of 10.

- When rounding, 5 is always rounded up (so 15 rounds to 20, etc.).

Code

1
2
3