2806. Account Balance After Rounded Purchase Easy
1/**
2 * [2806] Account Balance After Rounded Purchase
3 *
4 * Initially, you have a bank account balance of 100 dollars.
5 * You are given an integer purchaseAmount representing the amount you will spend on a purchase in dollars, in other words, its price.
6 * When making the purchase, first the purchaseAmount is rounded to the nearest multiple of 10. Let us call this value roundedAmount. Then, roundedAmount dollars are removed from your bank account.
7 * Return an integer denoting your final bank account balance after this purchase.
8 * Notes:
9 *
10 * 0 is considered to be a multiple of 10 in this problem.
11 * When rounding, 5 is rounded upward (5 is rounded to 10, 15 is rounded to 20, 25 to 30, and so on).
12 *
13 *
14 * <strong class="example">Example 1:
15 * <div class="example-block">
16 * Input: <span class="example-io">purchaseAmount = 9</span>
17 * Output: <span class="example-io">90</span>
18 * Explanation:
19 * The nearest multiple of 10 to 9 is 10. So your account balance becomes 100 - 10 = 90.
20 * </div>
21 * <strong class="example">Example 2:
22 * <div class="example-block">
23 * Input: <span class="example-io">purchaseAmount = 15</span>
24 * Output: <span class="example-io">80</span>
25 * Explanation:
26 * The nearest multiple of 10 to 15 is 20. So your account balance becomes 100 - 20 = 80.
27 * </div>
28 * <strong class="example">Example 3:
29 * <div class="example-block">
30 * Input: <span class="example-io">purchaseAmount = 10</span>
31 * Output: <span class="example-io">90</span>
32 * Explanation:
33 * 10 is a multiple of 10 itself. So your account balance becomes 100 - 10 = 90.
34 * </div>
35 *
36 * Constraints:
37 *
38 * 0 <= purchaseAmount <= 100
39 *
40 */
41pub struct Solution {}
42
43// problem: https://leetcode.com/problems/account-balance-after-rounded-purchase/
44// discuss: https://leetcode.com/problems/account-balance-after-rounded-purchase/discuss/?currentPage=1&orderBy=most_votes&query=
45
46// submission codes start here
47
48impl Solution {
49 pub fn account_balance_after_purchase(purchase_amount: i32) -> i32 {
50 0
51 }
52}
53
54// submission codes end
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn test_2806() {
62 }
63}
64
Back
© 2025 bowen.ge All Rights Reserved.