当前位置:网站首页>leetcode:5259. 计算应缴税款总额【简单模拟 + 看看在哪个区间】
leetcode:5259. 计算应缴税款总额【简单模拟 + 看看在哪个区间】
2022-06-12 18:36:00 【白速龙王的回眸】
分析
看看自己的前落在哪个区间,然后前面的区间全加起来
最后一个区间就加上当前多出来的那部分即可
ac code
class Solution:
def calculateTax(self, brackets: List[List[int]], income: int) -> float:
ans = 0
n = len(brackets)
if income <= brackets[0][0]:
return income * brackets[0][1] / 100
else:
for i in range(n):
if i == 0:
ans += brackets[0][0] * brackets[0][1] / 100
else:
if income >= brackets[i - 1][0] and income <= brackets[i][0]:
ans += (income - brackets[i - 1][0]) * brackets[i][1] / 100
break
else:
ans += (brackets[i][0] - brackets[i - 1][0]) * brackets[i][1] / 100
return ans
总结
简单模拟 但如果超出了全部区间的最后一部分怎么算呢?
题目应该说清楚一点
边栏推荐
猜你喜欢
Introduction to reinforcement learning and analysis of classic items 1.3
JS for Fibonacci sequence
Two months later, my second listing anniversary [June 2, 2022]
Why my order by create_ Time ASC becomes order by ASC
VirtualLab基础实验教程-5.泊松亮斑
How to modify the authorization of sina Weibo for other applications
Problems that the sap Spartacus e-commerce cloud UI shipping method does not display in the unit test environment
Review of MySQL (I): go deep into MySQL
Basic SQL statement - select (single table query)
USB to serial port - maximum peak serial port baud rate vs maximum continuous communication baud rate
随机推荐
C language practice (4) -- multiplication and division of large numbers
Gossip about the source code of redis 89
Summary of interview questions
HTTP cache < strong cache and negotiation cache >
Changes in the third generation dri
Why my order by create_ Time ASC becomes order by ASC
Regression analysis based on elasticnetcv
js求斐波那契数列
用一个性能提升了666倍的小案例说明在TiDB中正确使用索引的重要性
232-CH579M学习开发-以太网例程-TCP服务器(项目应用封装,局域网或广域网测试)
Write a select based concurrent server
【sql语句基础】——查(select)(单表查询)
C语言学习——数据在内存中的存储
配送交付时间轻量级预估实践-笔记
Remote gadget putty (Alibaba cloud mirror station address sharing)
JS judge palindromes
Leetcode topic [string] - Sword pointing offer 05- replace spaces
Shenzhen has been shut down for 7 days since March 14. Home office experience | community essay solicitation
Review of MySQL (I): go deep into MySQL
Gospel of audio and video developers, rapid integration of AI dubbing capability