Calculate Amount Paid in Taxes LeetCode solution in C++

1
class Solution {
2
public:
3
double calculateTax(vector<vector<int>> &brackets, int income) {
4
double ans = 0;
5
int back = 0;
6
for (auto x : brackets) {
7
int upper = x[0], percent = x[1];
8
if (upper > income) {
9
ans += (income - back) * percent;
10
break;
11
} else
12
ans += (upper - back) * percent;
13
back = upper;
14
}
15
return (ans / 100);
16
}
17
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0