Leetcode Problem 2806. Account Balance After Rounded Purchase

2806. Account Balance After Rounded Purchase

Leetcode Solutions

Rounding to Nearest Multiple of

  1. Calculate the remainder of purchaseAmount when divided by 10 (i.e., purchaseAmount % 10).
  2. If the remainder is less than 5, subtract the remainder from purchaseAmount to round down.
  3. If the remainder is 5 or greater, add (10 - remainder) to purchaseAmount to round up.
  4. Subtract the rounded purchaseAmount from the initial balance of 100 to get the final account balance.
  5. Return the final account balance.
UML Thumbnail

Iterative Comparison to Nearest Multiples of

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...