Skip to content

Latest commit

 

History

History
31 lines (25 loc) · 671 Bytes

File metadata and controls

31 lines (25 loc) · 671 Bytes

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