Skip to content

Latest commit

 

History

History

calculate-amount-paid-in-taxes

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Calculate amount paid in taxes

Problem link

Solutions

Solution.cpp

// https://leetcode.com/problems/calculate-amount-paid-in-taxes

class Solution {
 public:
  double calculateTax(vector<vector<int>>& brackets, int income) {
    int prev = 0;
    double ret = 0;
    for (const auto& v : brackets) {
      if (income <= v[0]) {
        ret += (income - prev) * v[1] / 100.;
        break;
      }
      ret += (v[0] - prev) * v[1] / 100.;
      prev = v[0];
    }
    return ret;
  }
};

Tags