Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0b5a511

Browse files
solves #2806: account balance after rounded purchases
1 parent a36d8d5 commit 0b5a511

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

‎README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,5 +842,5 @@
842842
| 2784 | [Check if Array is Good](https://leetcode.com/problems/check-if-array-is-good) | [![Java](assets/java.png)](src/CheckIfArrayIsGood.java) | |
843843
| 2788 | [Split Strings by Separator](https://leetcode.com/problems/split-strings-by-separator) | [![Java](assets/java.png)](src/SplitStringsBySeparator.java) | |
844844
| 2798 | [Number of Employees Who Met the Target](https://leetcode.com/problems/number-of-employees-who-met-the-target) | [![Java](assets/java.png)](src/NumberOfEmployeesWhoMetTheTarget.java) | |
845-
| 2806 | [Account Balance After Rounded Purchase](https://leetcode.com/problems/account-balance-after-rounded-purchase) | | |
845+
| 2806 | [Account Balance After Rounded Purchase](https://leetcode.com/problems/account-balance-after-rounded-purchase) | [![Java](assets/java.png)](src/AccountBalanceAfterRoundedPurchase.java) | |
846846
| 2810 | [Faulty Keyboard](https://leetcode.com/problems/faulty-keyboard) | | |
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// https://leetcode.com/problems/account-balance-after-rounded-purchase
2+
// T: O(1)
3+
// S: O(1)
4+
5+
public class AccountBalanceAfterRoundedPurchase {
6+
public int accountBalanceAfterPurchase(int purchaseAmount) {
7+
final int purchaseAmountRounded = (int) (Math.round(purchaseAmount / 10.0) * 10);
8+
return 100 - purchaseAmountRounded;
9+
}
10+
}

‎src/HelloWorld.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ public int query(int a, int b) {
2626
}
2727

2828
public static void main(String[] args) {
29-
HelloWorld helloWorld = new HelloWorld(new int[] {1, 2, 3, 4, 5, 1, 2, 1, 2}, 5);
30-
System.out.println(helloWorld.query(0, 0));
31-
System.out.println(helloWorld.query(0, 1));
32-
System.out.println(helloWorld.query(0, 2));
33-
System.out.println(helloWorld.query(3, 3));
34-
System.out.println(helloWorld.query(20, 30));
35-
System.out.println(helloWorld.query(10, 15));
29+
30+
System.out.println(Math.round(10.5));
3631
}
3732
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /