当前位置:网站首页>LeetCode 5259. 计算应缴税款总额
LeetCode 5259. 计算应缴税款总额
2022-06-13 09:06:00 【Michael阿明】
文章目录
1. 题目
给你一个下标从 0 开始的二维整数数组 brackets ,其中 brackets[i] = [upperi, percenti] ,表示第 i 个税级的上限是 upperi ,征收的税率为 percenti 。税级按上限 从低到高排序(在满足 0 < i < brackets.length 的前提下,upperi-1 < upperi)。
税款计算方式如下:
- 不超过
upper0的收入按税率percent0缴纳 - 接着
upper1 - upper0的部分按税率percent1缴纳 - 然后
upper2 - upper1的部分按税率percent2缴纳 以此类推
给你一个整数 income 表示你的总收入。 返回你需要缴纳的税款总额。 与标准答案误差不超 10-5 的结果将被视作正确答案。
示例 1:
输入:brackets = [[3,50],[7,10],[12,25]], income = 10
输出:2.65000
解释:
前 $3 的税率为 50% 。需要支付税款 $3 * 50% = $1.50 。
接下来 $7 - $3 = $4 的税率为 10% 。需要支付税款 $4 * 10% = $0.40 。
最后 $10 - $7 = $3 的税率为 25% 。需要支付税款 $3 * 25% = $0.75 。
需要支付的税款总计 $1.50 + $0.40 + $0.75 = $2.65 。
示例 2:
输入:brackets = [[1,0],[4,25],[5,50]], income = 2
输出:0.25000
解释:
前 $1 的税率为 0% 。需要支付税款 $1 * 0% = $0 。
剩下 $1 的税率为 25% 。需要支付税款 $1 * 25% = $0.25 。
需要支付的税款总计 $0 + $0.25 = $0.25 。
示例 3:
输入:brackets = [[2,50]], income = 0
输出:0.00000
解释:
没有收入,无需纳税,需要支付的税款总计 $0 。
提示:
1 <= brackets.length <= 100
1 <= upperi <= 1000
0 <= percenti <= 100
0 <= income <= 1000
upperi 按递增顺序排列
upperi 中的所有值 互不相同
最后一个税级的上限大于等于 income来源:力扣(LeetCode) 链接:https://leetcode.cn/problems/calculate-amount-paid-in-taxes 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
2. 解题
- 按题意模拟
class Solution:
def calculateTax(self, brackets: List[List[int]], income: int) -> float:
ans = 0
prev = 0
for i in range(len(brackets)):
if income > 0:
val = brackets[i][0] - prev # 区间税额
money = min(val, income) # 要交税的金额
ans += money*brackets[i][1]/100 # 交税
income -= money # 更新剩余要交税的金额
prev = brackets[i][0] # 税的断点
else:
break
return ans44 ms 15.1 MB Python3
边栏推荐
- Redirect vulnerability analysis of network security vulnerability analysis
- Opencv gaussianblur() explanation (Sigma value)
- 线上调试工具Arthas高级
- 20211028 Stabilizability
- 20211115 矩阵对角化的充要条件;满秩矩阵不一定有n个线性无关的特征向量;对称矩阵一定可以对角化
- Tutorial (5.0) 02 Management * fortiedr * Fortinet network security expert NSE 5
- C language: shortcut keys commonly used in VS
- [QNX hypervisor 2.2 user manual] 4.5 building a guest
- JUC Unsafe
- transforms. ColorJitter(0.3, 0, 0, 0)
猜你喜欢

How to become a white hat hacker? I suggest you start from these stages

Online debugging tool Arthas advanced
![[security] how to counter attack from 0 to 1 to become a security engineer with zero Foundation](/img/4d/c33a3fcc3b45c2369e1f1f74a8d51b.png)
[security] how to counter attack from 0 to 1 to become a security engineer with zero Foundation

Solov2 nanny level tutorial (including environment configuration, training your own data set, code logic analysis, etc...) Updating ing

线上调试工具Arthas基础

JUC atomic reference and ABA problem

JUC 原子累加器 源码之 LongAdder

Exporting MySQL data table documents using Navicat

202012 CCF test questions

transforms. ColorJitter(0.3, 0, 0, 0)
随机推荐
Completely uninstall PostgreSQL under Linux
【最全面详细解释】背包问题详解
Sonar scan ignores the specified file
LeetCode 72. 编辑距离
CAS NO lock
Void* pointer
20211104 为什么相似矩阵的迹相同
[QNX hypervisor 2.2 user manual] 4.5.1 build QNX guest
20211005 Hermite矩阵及几个性质
LeetCode 剑指 Offer 30. 包含min函数的栈
LeetCode 1143. 最长公共子序列
Redirect vulnerability analysis of network security vulnerability analysis
Neo4j Environment Building
Necessary and sufficient conditions for diagonalization of 20211115 matrix; The full rank matrix does not necessarily have n linearly independent eigenvectors; Symmetric matrices must be diagonalized
LeetCode 6098. 统计得分小于 K 的子数组数目(前缀和+二分查找)
Talking about acid of database
The Jenkins console does not output custom shell execution logs
C language: callback function
LeetCode 202. 快乐数
Module build failed: TypeError: this. getOptions is not a function at Object. stylusLoader