Skip to content

Commit af47e8d

Browse files
authored
Create calculate-amount-paid-in-taxes.cpp
1 parent cd7f03b commit af47e8d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
// simulation
5+
class Solution {
6+
public:
7+
double calculateTax(vector<vector<int>>& brackets, int income) {
8+
double result = 0;
9+
int prev = 0;
10+
for (const auto& b : brackets) {
11+
result += max((min(b[0], income) - prev) * b[1] / 100.0, 0.0);
12+
prev = b[0];
13+
}
14+
return result;
15+
}
16+
};

0 commit comments

Comments
 (0)