当前位置:网站首页>2303. 计算应缴税款总额
2303. 计算应缴税款总额
2022-07-02 12:10:00 【紫菜(Nori)】
class Solution {
public:
double calculateTax(vector<vector<int>>& brackets, int income) {
double ans = 0;
for(int i = brackets.size() - 1; i > 0; --i){
auto &vec = brackets[i];
auto &vec1 = brackets[i - 1];
// 当income不在这个区间时直接跳过
if(vec[0] > income && vec1[0] > income){
continue;
}
// 中间的差值
int diff = income - vec1[0];
// 这部分差值所应该交的税,这里是实际值的100倍
ans += (diff * vec[1]);
// 当前剩余未计算的income
income = vec1[0];
}
// 计算最小的范围,应交的税,这里是实际值的100倍
ans += (income * brackets[0][1]);
// 计算实际税
ans /= 100;
return ans;
}
};边栏推荐
- Summary of the first three passes of sqli Labs
- Set set you don't know
- Guangzhou Emergency Management Bureau issued a high temperature and high humidity chemical safety reminder in July
- How to choose a third-party software testing organization for automated acceptance testing of mobile applications
- Solution of Queen n problem
- How does the computer set up speakers to play microphone sound
- 18_ Redis_ Redis master-slave replication & cluster building
- 14_ Redis_ Optimistic lock
- 终于搞懂了JS中的事件循环,同步/异步,微任务/宏任务,运行机制(附笔试题)
- 【LeetCode】695-岛屿的最大面积
猜你喜欢
随机推荐
Redux - detailed explanation
Leetcode skimming - remove duplicate letters 316 medium
Infra11199 database system
Steps for Navicat to create a new database
LeetCode刷题——两整数之和#371#Medium
Equipped with Ti am62x processor, Feiling fet6254-c core board is launched!
党史纪实主题公益数字文创产品正式上线
(Video + graphic) machine learning introduction series - Chapter 5 machine learning practice
LeetCode刷题——统计各位数字都不同的数字个数#357#Medium
Pytoch saves tensor to Mat file
16_ Redis_ Redis persistence
做好抗“疫”之路的把关人——基于RK3568的红外热成像体温检测系统
11_ Redis_ Hyperloglog_ command
Huffman tree: (1) input each character and its weight (2) construct Huffman tree (3) carry out Huffman coding (4) find hc[i], and get the Huffman coding of each character
yolo格式数据集处理(xml转txt)
[leetcode] 977 - carré du tableau ordonné
高考录取分数线爬取
LeetCode刷题——验证二叉树的前序序列化#331#Medium
Leetcode skimming -- sum of two integers 371 medium
MD5加密









