Skip to content

Commit 9566fad

Browse files
solves #2303: Calculate Amount Paid in Taxes n java
1 parent 4c93e45 commit 9566fad

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@
742742
| 2293 | [Min Max Game](https://leetcode.com/problems/min-max-game) | [![Java](assets/java.png)](src/MinMaxGame.java) | |
743743
| 2299 | [Strong Password Checker II](https://leetcode.com/problems/strong-password-checker-ii) | [![Java](assets/java.png)](src/StrongPasswordCheckerII.java) | |
744744
| 2300 | [Successful Pairs of Spells and Potions](https://leetcode.com/problems/successful-pairs-of-spells-and-potions) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | |
745-
| 2303 | [Calculate Amount Paid in Taxes](https://leetcode.com/problems/calculate-amount-paid-in-taxes) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | |
745+
| 2303 | [Calculate Amount Paid in Taxes](https://leetcode.com/problems/calculate-amount-paid-in-taxes) | [![Java](assets/java.png)](src/CalculateAmountPaidInTaxes.java) [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | |
746746
| 2315 | [Count Asterisks](https://leetcode.com/problems/count-asterisks) | [![Python](assets/python.png)](python/successfull_pairs_of_spells_and_potions.py) | |
747747
| 2316 | [Count Unreachable Pairs of Nodes in an Undirected Graph](https://leetcode.com/problems/count-unreachable-pairs-of-nodes-in-an-undirected-graph) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | |
748748
| 2319 | [Check if Matrix Is X-Matrix](https://leetcode.com/problems/check-if-matrix-is-x-matrix) | [![Python](assets/python.png)](python/count_unreachable_pair_of_node_in_an_undirectable_graph.py) | |

Diff for: src/CalculateAmountPaidInTaxes.java

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// https://leetcode.com/problems/calculate-amount-paid-in-taxes
2+
// T: O(|brackets|)
3+
// S: O(1)
4+
5+
public class CalculateAmountPaidInTaxes {
6+
public double calculateTax(int[][] brackets, int income) {
7+
double tax = 0;
8+
int ceiling = 0;
9+
for (int i = 0 ; i < brackets.length && income > 0 ; i++) {
10+
final int taxableIncome = Math.min(brackets[i][0] - ceiling, income);
11+
income -= taxableIncome;
12+
ceiling = brackets[i][0];
13+
tax += taxableIncome * ((double) brackets[i][1] / 100);
14+
}
15+
return tax;
16+
}
17+
}

0 commit comments

Comments
 (0)