Calculate Amount Paid in Taxes
算税
class Solution {
public double calculateTax(int[][] brackets, int income) {
int prev = 0;
double tax = 0d;
for(int[] b : brackets){
int d = b[0] - prev;
if(d <= income)
tax += ((double)b[1] / 100d) * d;
else
tax += ((double)b[1] / 100d) * (double)income;
income -= d;
if(income <= 0)
break;
prev = b[0];
}
return tax;
}
}